0

bind in javascript lets you bind a function to some value and in the returned function has this equal to the value.

if I have a function, is there a way to check that this inside this function is already bound to a value ? and to what value ?

--- adding example of what i want

function foo() { /*...*/ }

const bar = foo.bind(val); // val is any value

if am given only bar can i somehow reach to val

ashish singh
  • 6,526
  • 2
  • 15
  • 35
  • It's usually related to the context (whether the function is bound to a parent object or to the main context itself). In the global context, `this` in any function refers to `window`. Unless you are in strict mode, where `this` is undefined. You can find more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this – briosheje Oct 16 '18 at 16:50
  • 2
    Possible duplicate of [What object javascript function is bound to (what is its "this")?](https://stackoverflow.com/questions/14307264/what-object-javascript-function-is-bound-to-what-is-its-this) – Ayush Gupta Oct 16 '18 at 16:55
  • thanks @AyushGupta , will close this one – ashish singh Oct 16 '18 at 16:56

0 Answers0