Skip to content

Commit cfe411e

Browse files
committed
fine tuning previous notes
1 parent ea9bea2 commit cfe411e

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Javascript/call-apply-bind/bind-why-its-needed.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ console.log(retrieveX()) // => 9 Because here the function gets invoked at the g
3535
const boundX = retrieveX.bind(obj)
3636
console.log(boundX()) // => 70
3737
```
38+
### Further Reading
39+
[https://stackoverflow.com/questions/41391288/why-is-javascript-bind-necessary](https://stackoverflow.com/questions/41391288/why-is-javascript-bind-necessary)

Javascript/call-apply-bind/call-function-basics-1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In JavaScript all functions are object methods.
44

5-
If a function is not a method of a JavaScript object, it is a function of the global object (see previous chapter).
5+
If a function is not a method of a JavaScript object, it is a function of the global object.
66

77
```js
88
var person = {

Javascript/call-apply-bind/call-function-basics-2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ obj.func.call(obj) // => undefined
4848
obj.func2.call(obj) // => 15, accessing the
4949
```
5050

51-
The first invocation of f() will display the value of 10, because this references the global object. The second invocation (via the call method) however, will display the value 15. 15 is the value of the x property inside object o.
51+
The first invocation of f() will display the value of 10, because this references the global object. The second invocation (via the call method) however, will display the value 15. 15 is the value of the x property inside object obj.
5252

5353
### The call() method invokes the function and uses its first parameter as the this pointer inside the body of the function. In other words - we've told the runtime what object to reference as 'this' while executing inside of function f().
5454

Javascript/this-keyword/this-example-custom-Array-Prototype-method.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ console.log(a); // [1, 2, 3, 4, 5, 1, 4, 9, 16, 25]
1616
result.push(this[i] ** 2)
1717
}
1818
return [...this, ...result]
19-
} */
19+
}
20+
*/
21+
22+
/*
23+
[
24+
1, 2, 3, 4, 5,
25+
1, 4, 9, 16, 25
26+
]
27+
28+
*/
29+
30+
31+
// Below will produce slightly different result, the last element will be NaN
2032

2133
Array.prototype.multiply = function() {
2234
let result = []
@@ -29,4 +41,14 @@ Array.prototype.multiply = function() {
2941
let myArr = [1, 2, 3, 4, 5]
3042

3143
console.log(myArr.multiply())
44+
/*
45+
[
46+
1, 2, 3, 4, 5,
47+
4, 9, 16, 25, NaN
48+
]
49+
50+
*/
51+
52+
53+
3254
```

0 commit comments

Comments
 (0)