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());

 

相关文章:

  • 2021-07-19
  • 2021-09-23
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2022-12-23
  • 2022-01-04
  • 2022-02-24
  • 2021-12-29
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案