【发布时间】:2013-06-03 21:04:42
【问题描述】:
这段代码
class Foo
bar: []
test = new Foo()
test.bar.push('b')
test2 = new Foo()
console.log test2.bar
将产生输出['b']。怎么可能?
编辑:
这是 CoffeScript 生成的:
// Generated by CoffeeScript 1.4.0
var Test, test, test2;
Test = (function() {
function Test() {}
Test.prototype.a = [];
return Test;
})();
test = new Test();
test.a.push('b');
test2 = new Test();
console.log(test2.a);
因此,下面写的完全正确。谢谢各位。
【问题讨论】:
-
你用什么语言写的?
-
如果原型上定义了
bar,那么这是可能的。 -
@SLaks 这似乎是咖啡脚本
-
我认为您将其设为“类”变量。
-
抱歉,这是咖啡脚本
标签: node.js coffeescript