This article describes the replication and inheritance of js objects. Share it for your reference. The details are as follows:
Copy the code as follows:<script type="text/javascript">
Object.prototype.extend = function(obj){
//In the function, copy the obj attribute to itself
for(var k in obj){
if(obj.hasOwnProperty(k)){
if(this[k] == undefined){
this[k] = obj[k];
}
}
}
}
var kitty = {color:'yellow',climb:function(){alert('I can climb trees');}};
var tiger = {color:'yellow and black'};
tiger.extend(kitty);
tiger.climb();
</script>
I hope this article will be helpful to everyone's JavaScript programming.