stargateatlantis
asked on
Having trouble understanding javascript bind
I took a look at the following url and explanation but still don't get it
https://developer.mozilla. org/en-US/ docs/Web/J avaScript/ Reference/ Global_Obj ects/Funct ion/bind
Can somebody explain it better to me
https://developer.mozilla.
Can somebody explain it better to me
ASKER
Can you bind a object that contains a function??
Yes, you can use any object as context for the function.
You could even use something like "a string" or 42 as context, then the context would be a String object or a Number object, respectively.
If you would use null or undefined as context, the function would get the window object as context.
You could even use something like "a string" or 42 as context, then the context would be a String object or a Number object, respectively.
If you would use null or undefined as context, the function would get the window object as context.
ASKER
is there a more complex example
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help that is what I was looking for
Example:
Open in new window
The bind method allows you to create a function reference that will act as if you called it as a method in an object, without the function actually being part of the object.
Example:
Open in new window