【发布时间】:2017-03-04 01:49:09
【问题描述】:
我正在制作一个文件系统,但不知道如何添加“父”属性。
目前我认为我的问题是我无法调用尚未声明的函数,但我不知道如何逃避这个循环逻辑。
当前的错误是:
Uncaught TypeError: inputDir.getParentDirectory is not a function
我的代码是:
var file = function(FileName,inputDir,isDir){
this.Name=FileName;
this.CurrentDir=inputDir;
this.isDirectory = isDir;
this.size = 0;
this.timeStamp = new Date();
if(isDir===true){
this.subfiles = [];
}
if(inputDir!==null){
this.parentDir = inputDir.getParentDirectory();
}
this.rename = function(newName){
this.Name = newName;
};
this.updateTimeStamp = function(){
this.timeStamp = new Date();
};
};
file.prototype.getParentDirectory = function(){
return this.parentDir;
};
var fileSystem = function(){
this.root = new file("root",null,true);
this.createFile = function(name,currentDirectory,isDirectory){
var f = new file(name,currentDirectory,isDirectory);
currentDirectory.subfiles.push(f);
};
};
var myComputer = new fileSystem();
myComputer.createFile("Desktop","root",true);
【问题讨论】:
-
此代码有效...是否缺少某些东西?
-
是的,对不起。我添加了我的第一个声明,即根目录。根的父级显然必须为空,这会导致很多问题。我收到了我在上面发布的那个错误
标签: javascript file tree directory parent