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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| function make(name,size,price){ var o = new Object(); o.name = name; o.size = size; o.price = price; o.showPrice = function(){ console.log(this.price); }; return o; } var suit = make('nike','xl',666);
function Make(name,size,price){ this.name = name; this.size = size; this.price = price; this.showPrice = function(){ console.log(this.price); }; } var suit = new Make('nike','xl',666);
function Make(){ } Make.prototype.name = 'nike'; Make.prototype.size = 'xl'; Make.prototype.price = 666; Make.prototype.showPrice = function(){ console.log(this.price); }
var suit1 = new Make(); var suit2 = new Make(); suit1.name = '360'; console.log(suit1.name); console.log(suit2.name); delete suit1.name; console.log(suit1.name);
function Make(name,size,price){ this.name = name; this.size = size; this.price = price; this.number = 2; } Make.prototype = { constructor : Make, showPrice : function(){ console.log(this.price); } }
var suit1 = new Make('nike','xl',666); var suit2 = new Make('360','l',233); console.log(suit1.name === suit2.name); console.log(suit1.showPrice === suit2.showPrice);
|