JS understanding the weird parts 4-50 call apply bind
4-50 call(), apply(), and bind()
bigword alert : Function currying
creating a copy of a function but with some preset parameters.
The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.REF
bind 複製function,並將其中的 this 設成給定的物件,回傳複製的function
- The call() method calls a function with a given this value and arguments provided individually.REF
call 將function中的this改為thisArg, 並用後面的參數invoked 該function
- The apply() method calls a function with a given this value and arguments provided as an array REF
apply和call功能相同,差別只有function的參數要用array傳入
1 |
|
1 |
|
When is this used in real life?
- function borrowing
1 |
|
- function currying
1 |
|