1
正如标题中所述:当从CoffeeScript编译类时,是否有强制使用JavaScript中的括号表示法的方法?从CoffeeScript编译为JavaScript时强制使用括号表示法
一个简单的例子是
的CoffeeScript
class test
myMethod:() ->
1
编译的JavaScript没有括号符号
var test;
test = (function() {
function test() {}
test.prototype.myMethod = function() {
return 1;
};
return test;
})();
编译的JavaScript带支架符号
var test;
test = (function() {
function test() {}
test.prototype['myMethod'] = function() {
return 1;
};
return test;
})();
请注意,在第二个输出中,使用方括号表示方法myMethod()
。
我需要这个,以便我可以通过Google Closure Compiler运行输出,并且仍然保留我的方法的名称,这需要括号表示法,否则名称也会被缩小。
我不记得谷歌关闭编译器...你需要它丑化和缩小? – cl0udw4lk3r
@ cl0udw4lk3r和一些优化我的代码,是的。 – Sirko