1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| function merge (a, b){ if (a && b) { for (var key in b) { a[key] = b[key]; } } return a; };
function My() { this.sum = 0; }
My.prototype.add = function (a, b) { this.sum = a + b; return this; };
My.prototype.sub = function (b, c) { this.sum -= b + c; return this; }; var my = new My(); console.log(my.add(1, 6).sub(3, 4).sum);
function Person(options) { if(!(this instanceof Person)){ return new Person(options) } }
|