Hello!
There are 2 objects
var x={color:red} var y={foo:'bar',hoo:3} How through the prototype to copy all the properties of the object y to x. For new browsers, everything is OK through proto , and for proto through prototype I don’t see how.
Hello!
There are 2 objects
var x={color:red} var y={foo:'bar',hoo:3} How through the prototype to copy all the properties of the object y to x. For new browsers, everything is OK through proto , and for proto through prototype I don’t see how.
Object.prototype.extend = function( o ) { for( var i in o ) { if( o.hasOwnProperty(i) ) { this[i] = o[i]; } } } var x={ color: 'red' }; var y={ foo : 'bar', hoo:3 }; x.extend( y ); console.log( x ); for in loop, google and read, if you don’t know the hasOwnProperty method - likewise. The rest should be clear (actually there is nothing more there) Please - ZowieTry this method:
Object.prototype.clone = function () { var instance = {}; for (i in this) { if (i == 'clone') continue; if (this[i] && typeof this[i] == "object") { instance[i] = this[i].clone(); } else instance[i] = this[i] } return instance; }; Source: https://ru.stackoverflow.com/questions/88878/
All Articles