Function.prototype.bind()

486 ワード

ビッドの最も直接的な作用はthisの指向を変えることです.
const William = {
 sex: ' ',
 Nation: '   ',
 work: '  '
};

const getSex = function () {
 console.log(this.sex);
};

const getNation = function () {
 console.log(this.Nation);
};

const getWork = function () {
 console.log(this.work);
};

getSex(); //       ,undefined

getNation(William); //       ,undefined

getNation.bind(William)(); //    
let boundgetWork = getWork.bind(William);
boundgetWork(); //