javascript - How to change the context of function using 'bind'? -


this question has answer here:

function greet(){    return 'hi ' + this.name; } greet = greet.bind({name: 'tom'}); greet(); // hi tom greet = greet.bind({name: 'harry'}); greet(); // hi tom (why??) 

'bind' should return new function new values 'this'. why not working?

once function binded custom object, cannot changed. can original function unchanged:

function greet(){   return 'hi ' + this.name; } greet1 = greet.bind({name: 'tom'}); greet1(); // hi tom greet1 = greet.bind({name: 'harry'}); greet1(); // hi harry 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -