Name
Function.bind() — return a function that invokes this as a method
Availability
ECMAScript 5
Synopsis
function.bind(o)function.bind(o,args...)
Arguments
oThe object to which this function should be bound.
args...Zero or more argument values that will also be bound.
Returns
A new function which invokes this function as a method of
o and passes it the arguments
args.
Description
The bind() method returns a
new function which invokes this function as a method of the object
o. The arguments passed to this function
consist of the args passed to bind() followed by whatever values are
passed to the new function.
Example
Suppose that f is a
function and we call the bind()
method like this:
varg=f.bind(o,1,2);
Now g is a new function and
the invocation g(3) is equivalent
to:
f.call(o,1,2,3);
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access