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

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -