【发布时间】:2011-11-08 14:38:54
【问题描述】:
我正在开发一种编译成javascript的编程语言,生成的代码包含太多重复,比如:
cls.$init = function(){
this.property1 = {};
this.anotherProperty = [1, 2, 3, 4];
this.yetAnotherProperty = "test";
/* etc */
}
可以使用with 语句将其变得更小(在这种情况下,当初始化许多属性时):
cls.$init = function(){
with(this){
property1 = {};
anotherProperty = [1, 2, 3, 4];
yetAnotherProperty = "test";
/* etc */
}
}
但问题是……我应该在生成的代码中使用with 语句吗? (后面就不修改了)
【问题讨论】:
-
根据googletechtalks 上的这个视频,它会对你的脚本产生影响
标签: javascript code-generation