好的,我正在使用Node.js开发一个项目,但在对象字面量中的键方面遇到了一些小问题。我有以下设置:
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
之类的动态变量和连接将不可用:( :(
如何在不必重新编写大块代码的情况下克服这种障碍最好的方法是什么。