Arrow function

node v8.12.0
version: 1.0.0
endpointsharetweet
// Arrow function is not affected by "call", "apply" or "bind" +function () { this.name = 'parent'; const childObj = { name: 'child', sayHi: () => console.log(this.name) }; console.log('1. Traditional: '); childObj.sayHi(); console.log('2. call / apply: '); childObj.sayHi.call(childObj); console.log('3. bind: '); const boundHi = childObj.sayHi.bind(childObj); boundHi(); console.log('4. all of them: '); boundHi.call(childObj); }();
Loading…

no comments

    sign in to comment