1 Function.prototype.method = function(name, func) {
2 if (!this.prototype[name]) {
3 this.prototype[name] = func;
4 }
5 };
6
7 Function.method('bind', function(that) {
8 //返回一个函数,调用这个函数就像它是那个对象的方法一样。
9 var method = this,
10 slice = Array.prototype.slice,
11 args = slice.apply(arguments, [1]);
12 return function() {
13 return method.apply(that, args.concat(slice.apply(arguments, [0])));
14 };
15 });
16
17 var x = function() {
18 return this.value;
19 }.bind({
20 value: 666
21 });
22
23 console.log(x());