JS: Function Call, Apply, Bind
function , when called, has a associated value called “this binding”.
In function definition body, the value of “this binding” is represented by the keyword
[see JS: “this” Binding]
When a function f is called in the form
x.f(…), the value of “this binding” is the object x.
The following are ways to let you call a function and explicitly pass a value of your choice for
f.call(obj, arg1, arg2 …) → evaluate
f(arg1, arg2 …) with f's
this keyword having value of obj.
f.apply(obj, array) → evaluate function
f with f's
this keyword have value of obj, and elements of the array array is passed to the function as arguments.
Reflect.apply ( f, this_binding, argList ) → Call
f with its
this keyword having value of this_binding, and with arguments of elements in argList.
[see JS: Reflect.apply]
f.bind(obj) → return a function such that it has the same behavior as f except f's
this value is always obj.
f.bind(obj, args …) → the new function will always be given the arguments args.
- JS: Define Function
- JS: Functional Programing
- JS: Arrow Function
- JS: Function Parameters
- JS: f Declaration vs Expression
- JS: Closure
- JS: Function Call, Apply, Bind
- JS: Function Argument Default Value
- JS: Function Rest Parameters
- JS: Function Argument Destructure
- JS: Function Object
- JS: Function.prototype
Patreon me $5. Ask me question on patreon