function Foo(a) {
this.a = a;
this.bar = function() {
console.log(this.a);
};
this.buz = function() {
this.a();
console.log('bzz');
};
}
,我就會有這個類的相當多的實例。我應該將方法轉移到原型嗎?
function Foo(a) {
this.a = a;
}
Foo.prototype = {
bar: function() {
console.log(this.a);
},
buz: function() {
this.a();
console.log('bzz');
}
}