3

I would bind my function directly when declaring my function, the following attempt fails:

(function f() {
  return this.a;
}).bind({a: 'qwerty'});


var g = f()    
console.log("g: ", g)

how achieve this result?

Any hint would be great, thanks

1 Answer 1

3

You need an assignment of the bound function. Function#bind returns a new function.

var f = function () {
        return this.a;
    }.bind({ a: 'qwerty' }),
    g = f()    

console.log("g:", g);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.