https://github.com/zakimohammed/javascript-elders
Exploring the JavaScript's elder functions named - apply, call and bind.
https://github.com/zakimohammed/javascript-elders
apply bind call javascript this-keyword
Last synced: 20 days ago
JSON representation
Exploring the JavaScript's elder functions named - apply, call and bind.
- Host: GitHub
- URL: https://github.com/zakimohammed/javascript-elders
- Owner: ZakiMohammed
- Created: 2021-09-13T07:12:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T20:54:35.000Z (over 4 years ago)
- Last Synced: 2025-03-03T19:18:34.164Z (over 1 year ago)
- Topics: apply, bind, call, javascript, this-keyword
- Language: JavaScript
- Homepage: https://codeomelet.com/posts/javascript-elders-call-apply-bind
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JavaScript Elders - Call, Apply, Bind
Exploring the JavaScript's elder functions named - call, apply and bind.
Link: https://codeomelet.com/posts/javascript-elders-call-apply-bind
---
For any given function:
```
function theFunction(argument1, argument2, ..., argumentN) {
// usage of this.property1, this.property2, ..., this.propertyN
// usage of param1, param2, ..., paramN
}
```
For any given object:
```
const theObject = { property1, property2, ..., propertyN };
```
---
Syntax for call:
```
const result = theFunction.call(theObject, param1, param2, ..., paramN);
```
Syntax for apply:
```
const result = theFunction.apply(theObject, [param1, param2, ..., paramN]);
```
Syntax for bind (works only for theObject):
```
const theNewFunction = theFunction.bind(theObject);
const result1 = theNewFunction(param1, param2, ..., paramN);
const result2 = theNewFunction(param1, param2, ..., paramN);
...
const resultN = theNewFunction(param1, param2, ..., paramN);
```