Name
Function.bind() — return a function that invokes this as a method
Availability
ECMAScript 5
Synopsis
function
.
bind
(
o
)
function
.
bind
(
o
,
args
...
)
Arguments
o
The 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:
var
g
=
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
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.