An open API service indexing awesome lists of open source software.

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.

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);
```