<script language="javascript"> //給Object對(duì)象增加靜態(tài)方法extend,該方法的作為復(fù)制source有所有屬性和方法到destination Object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; }
var dog = function(name) { this.name = name; } //將printName方法復(fù)制給dog.prototype Object.extend(dog.prototype, { printName:function() { alert(this.name); } } ); var a = new dog("dog"); a.printName(); </script>