Node.js 339 B

12345678910111213141516171819202122
  1. export default class Node {
  2. constructor(name, parent) {
  3. this.name = name;
  4. this.parent = parent;
  5. }
  6. get path() {
  7. const path = [];
  8. let node = this;
  9. while (node) {
  10. path.push(node.name);
  11. node = node.parent;
  12. }
  13. return path.reverse().join('/');
  14. }
  15. get isRoot() {
  16. return !this.parent;
  17. }
  18. }