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

bind的使用

时间:2019-06-16 18:45:35      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:context   console   strong   contex   ons   type   fun   text   func   

bind: 改变this的指向,返回一个新函数

let obj = {
name: ‘jason888‘
}

function fun(name,age){
//console.log(888);
//console.log("this:",this);
console.log("this.name:",this.name);
// console.log("arguments:",arguments.callee);
// console.log("Array:",Array.prototype);
// console.log(name);
// console.log(age);
}

//let foo = fun.bind(obj,‘meay‘,33);
//foo();

//bind: 改变this指向,返回一个新函数
Function.prototype.bind2 = function(context){
let self = this;
return function(){
self.apply(context,Array.prototype.slice.call(arguments,1))
}
}

let foo = fun.bind2(obj,‘meay‘,33);
foo();

bind的使用

标签:context   console   strong   contex   ons   type   fun   text   func   

原文地址:https://www.cnblogs.com/zhaodagang8/p/11032432.html

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