我使用构建工具通过 JavaScript 源代码进行构建。
此工具会产生错误
error: SyntaxError: missing name after . operator
当使用 this._parts[part]
时,如下例所示。
我想知道如何重写此代码,以便考虑到 this._parts
包含动态填充的字符串数组,错误将会消失。
var html = '';
Object.keys(this._parts).forEach(function (part, index) {
html += this._parts[part].class; // error here
}, this);
注释:我正在使用 dojo 构建工具来处理代码,并且我知道使用 pragma 从构建过程中排除部分代码,在这里我有兴趣重写代码本身,谢谢。
最佳答案
使用括号表示法
this['_parts'][part]
关于javascript - 如何重写部分代码以绕过错误 : SyntaxError: missing name after . 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34020995/