该代码非常适合WHITESPACE_ONLY选项。但是在高级模式下,点表示法不起作用。但括号符号仍然有效。
以下是JSON对象:
{
'title' : 'The title',
'type' : 'SIM',
'description' : 'Build your own description.',
'iconclass' : goog.getCssName('img-icons-bs')
}以下是代码:
console.log('this.obj_ = ' + JSON.stringify(this.obj_));
console.log('this.obj_.iconclass = ' + this.obj_.iconclass);
console.log('this.obj_[iconclass] = ' + this.obj_['iconclass']);输出:
> this.obj_ = {"title":"The title","type":"SIM","description":"Build
> your own description.","iconclass":"img-icons-r"}
> this.obj_.iconclass = undefined
> this.obj_[iconclass] = img-icons-r问题出在哪里?
发布于 2016-04-04 01:06:16
确保你的理解编译模式之间的差异。
在ADVANCED_OPTIMIZATIONS中,闭包编译器重命名由虚线符号引用的属性,而不使用引号重命名属性。示例:
原始
var foo = {};
foo.bar = foo['bar'] = 47;编译
var a = {};
a.b = a.bar = 47;由于JSON对象属性对编译器是隐藏的,所以必须始终使用引号来访问它们。
// This line is incorrect - the compiler can rename '.iconclass'
console.log('this.obj_.iconclass = ' + this.obj_.iconclass);
// This line is correct - ["iconclass"] is safe from renaming.
console.log('this.obj_[iconclass] = ' + this.obj_['iconclass']);发布于 2016-04-02 22:26:29
由于您从未定义过game,因此它将返回未定义的下一行。再检查一次输出。你读错了。
console.log('this.obj_[iconclass] = ' + this.game_['iconclass']); 如果将行更改为以下内容,则对括号和点表示法都适用:
console.log('this.obj_.iconclass = ' + this.obj_.iconclass);
console.log('this.obj_[iconclass] = ' + this.obj_['iconclass']);

https://stackoverflow.com/questions/36379364
复制相似问题