ES5 Function複製物件 2018-04-11
function Calc(num1, num2, color) {
this.num1 = parseInt(num1);
this.num2 = parseInt(num2);
this.color = color.toString();
this.add = function() {
return this.num1 + this.num2;
}
this.substract = function() {
return this.num1 - this.num2;
}
}
var x = new Calc(2, 3, 'Black');
var y = new Calc(3, 4, 'Red');
console.log(x.add());
console.log(y.substract());
var x = { a: function () { ... }, b: function() { ... } ... } ;
這方法似乎不行用new.