Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bind function inline Javascript

Tags:

javascript

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

like image 211
Webwoman Avatar asked Nov 26 '25 19:11

Webwoman


1 Answers

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);
like image 72
Nina Scholz Avatar answered Dec 02 '25 15:12

Nina Scholz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!