摘要:
1 if (typeof Object.beget !== 'function') { 2 Object.beget = function(o) { 3 var F = function() {}; 4 F.prototype = o; 5 return new F(); 6 }; 7 } 8 9 var myMammal = {10 name: 'Herb the Mammal',11 get_name: function() {12 return this.name;13 },14 ... 阅读全文
posted @ 2012-07-12 22:15
小猩猩君
阅读(285)
评论(0)
推荐(0)
摘要:
Object.create方法创建一个使用原对象作为其原型的新对象。1 if (typeof Object.create !== 'function') {2 Object.create = function (o) {3 function F() {}4 F.prototype = o;5 return new F();6 };7 }8 newObject = Object.create(oldObject); 阅读全文
posted @ 2012-07-12 21:49
小猩猩君
阅读(275)
评论(0)
推荐(0)
摘要:
1 var memoizer = function(memo, fundamental) { 2 var shell = function(n) { 3 var result = memo[n]; 4 if (typeof result !== 'number') { 5 result = fundamental(shell, n); 6 memo[n] = result; 7 } 8 ... 阅读全文
posted @ 2012-07-12 12:49
小猩猩君
阅读(193)
评论(0)
推荐(0)
摘要:
var memoizer = function(memo, fundamental) { var shell = function(n) { var result = memo[n]; if (typeof result !== 'number') { result = fundamental(shell, n); memo[n] = result; } return result; ... 阅读全文
posted @ 2012-07-12 12:48
小猩猩君
阅读(223)
评论(0)
推荐(0)
摘要:
1 Function.prototype.method = function(name, func) { 2 if (!this.prototype[name]) { 3 this.prototype[name] = func; 4 } 5 }; 6 7 Function.method('curry', function() { 8 var slice = Array.prototype.slice, 9 args = slice.apply(arguments),10 that = this;11 retur... 阅读全文
posted @ 2012-07-12 12:30
小猩猩君
阅读(136)
评论(0)
推荐(0)

浙公网安备 33010602011771号