var module = {
x:10,
getX: function(){
return this.x
}
}
var unboundGetX = module.getX
console.log(unboundGetX()) // undefined
var boundGetX = unboundGetX.bind(module)
console.log(boundGetX()) // 10
var module = {
x:10,
getX: function(){
return this.x
}
}
var unboundGetX = module.getX
console.log(unboundGetX()) // undefined
var boundGetX = unboundGetX.bind(module)
console.log(boundGetX()) // 10
本文标题:Function.prototype.bind 典型例子
本文链接:https://www.haomeiwen.com/subject/dcwgyqtx.html
网友评论