码迷,mamicode.com
首页 > 其他好文 > 详细

Function.prototype.bind

时间:2015-05-11 13:11:32      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

Function.prototype.bind = function (scope) {
     var fn = this ;
     return function () {
         return fn.apply(scope);
     };
}
var foo = {
     x: 3
}
 
var bar = function (){
     console.log( this .x);
}
 
bar(); // undefined
 
var boundFunc = bar.bind(foo);
 
boundFunc(); // 3


Function.prototype.bind

标签:

原文地址:http://my.oschina.net/u/1992917/blog/413199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!