篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript OOP w / Javascript相关的知识,希望对你有一定的参考价值。
/*
Implement a simplified filesystem using Object Oriented Programming
consisting of only Files and Directories. Directories can contain
Files or other Directories. Both Files and Directories should have
attributes 'name', 'filesize', 'writeable'.
Given a 'tree' that looks like
Directory
- File
- Directory
- Directory
- File
Change the 'writeable' attribute for each object from true to false
*/
class Directory extends File {
constructor(name, filesize, writeable, children = []) {
super(name, filesize, writeable);
this.children = children;
}
setWriteable(writeable) {
super(writeable);
for (const child of this.children) {
child.setWritable(writeable);
}
}
}
class File {
constructor(name, filesize, writeable) {
this.name = name;
this.filesize = filesize;
this.writeable = writeable;
}
setWriteable(writeable) {
this.writeable = writeable;
}
}
以上是关于javascript OOP w / Javascript的主要内容,如果未能解决你的问题,请参考以下文章