首页 > 其他 > 详细

Function.prototype.bind

时间:2015-05-11 13:09:20      阅读:102      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!