您的位置:首页 > 其它

绑定函数bind()

2013-10-22 15:06 225 查看
var name = "ww";
var page = {

init : function(name){
//this.name = "uu";
console.log(this.name);
document.body.onclick = function(){
console.log("winter's wind, 走走停停");
};
}
};
var one = {
name : "life is floower"
};
var slice = Array.prototype.slice;
if(typeof Function.prototype.bind !== "function"){
Function.prototype.bind = function(Args){
var fn = this,  args = slice.call(Args, 1);// arguments 是类数组 没有slice 方法 需要调用
return function(){
fn.apply(Args[0], args);
};
};
}

page.init.bind(one)(); //life is floower
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: