Javascript中对象文字的动态键
好吧,我正在努力开发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
和连接不可用:( :(
什么是克服这样的障碍而不必重写大块代码的最佳方法。
慕的地8271018
相关分类