prototype.js中Object.extend源码学习。
Object.extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination;} |
example
var o = { test: 'test it', sex: 'man', info: function() { return this.test + " and " + this.sex; }, ivk: function() { return this.info.apply(this); // invoke this.info function }}for (var p in Object) { console.log('Object["' + p + '"] = ' + Object[p]);}Object.extend(Object, o);for (var p in Object) { console.log('Object["' + p + '"] = ' + Object[p]);}console.log(Object.ivk()); |