Closure
An inner function has always access to the variables and parameters of its outer function, even after the outer function has returned.
1 | function retirement(retirementAge) { |
Bind, Call and Apply
call
and apply
basically are used to define the execution context of the current method.
The difference between bind
and call
is that bind
will return a function reference that can be used later, but call
will only return the result from the immediate execution of the function.
1 | var john = { |
this
keyword
In ES5
this
keyword refers to the object it belongs to.
- In a method,
this
refers to the owner object - Alone,
this
refers to the global object - In a function,
this
refers to the global object - In a function, in strict mode,
this
isundefined
- In an event,
this
refers to the element that received the event - Methods like
call()
, andapply()
can referthis
to any object
1 | var box5 = { |
In ES6
1 | const box6 = { |