好的,我正在致力于 Nodes 中的一个项目,我遇到了一个关于对象文字中的键的小问题,我有以下设置:
var required = {
directories : {
this.applicationPath : "Application " + this.application + " does not exists",
this.applicationPath + "/configs" : "Application config folder does not exists",
this.applicationPath + "/controllers" : "Application controllers folder does not exists",
this.applicationPath + "/public" : "Application public folder does not exists",
this.applicationPath + "/views" : "Application views folder does not exists"
},
files : {
this.applicationPath + "/init.js" : "Application init.js file does not exists",
this.applicationPath + "/controllers/index.js" : "Application index.js controller file does not exists",
this.applicationPath + "/configs/application.js": "Application configs/application.js file does not exists",
this.applicationPath + "/configs/server.js" : "Application configs/server.js file does not exists"
}
}
你们中的很多人会看到这个并认为它看起来没问题,但是编译器一直告诉我缺少一个 :
(冒号) ,其实不是,看起来好像是 +
或者 .
都在影响编译器。
现在我相信(不确定) ,对象文字是在编译时创建的,而不是在运行时创建的,这意味着动态变量(如 this.applicationPath
和连接)将不可用: (: (
克服这种障碍的最好方法是什么,而不需要重写大量的代码。