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,
thisrefers to the owner object - Alone,
thisrefers to the global object - In a function,
thisrefers to the global object - In a function, in strict mode,
thisisundefined - In an event,
thisrefers to the element that received the event - Methods like
call(), andapply()can referthisto any object
1 | var box5 = { |
In ES6
1 | const box6 = { |