Skip to content

Commit 4838cd0

Browse files
committed
updated nots curried functions and also call and aplly
1 parent 35c99d1 commit 4838cd0

File tree

8 files changed

+93
-15
lines changed

8 files changed

+93
-15
lines changed

CSS/z-index.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```
2+
div {
3+
z-index: 1; /* integer */
4+
}
5+
```
6+
7+
**The z-index property in CSS controls the vertical stacking order of elements that overlap. As in, which one appears as if it is physically closer to you. z-index only affects elements that have a position value other than static (the default).**
8+
9+
### Why z-index may not give expected results sometimes
10+
11+
The element doesn’t have its position set
12+
One of the other guidelines that determine stacking order is if an element has its position set or not.
13+
14+
To set position for an element, add the CSS position property to anything other than static, like relative or absolute. (You can read more about it in this article that I wrote.)
15+
16+
According to this rule, positioned elements will display on top of unpositioned elements.
17+
18+
### Further Reading
19+
20+
[https://coder-coder.com/z-index-isnt-working/](https://coder-coder.com/z-index-isnt-working/)

Javascript/call-function.md renamed to Javascript/call-apply-bind/call-function.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ There is not big difference in performance. But we can say call is bit faster as
99
### Both call() and apply() are methods we can use to assign the this pointer for the duration of a method invocation.
1010

1111
```js
12-
global.x = 10;
13-
// To run this file in my vs-code or in terminal (i.e. where I am in node env)
14-
// I have to use global . where as < var x = 10 > will work in browser dev-tool
12+
global.x = 10
13+
/* To run this file in my vs-code or in terminal (i.e. where I am in node env),
14+
I have to use global . where as < var x = 10 > will work in browser dev-tool
1515
16-
// var x = 10
16+
var x = 10 */
1717

18-
var o = { x: 15 };
18+
var o = { x: 15 }
1919

20-
function f () {
21-
console.log(this.x);
20+
function f() {
21+
console.log(this.x)
2222
}
2323

24-
f(); // => 10
25-
26-
f.call(o); // => 15
24+
f() // => 10
2725

26+
f.call(o) // => 15
2827
```
2928

3029
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.
@@ -41,19 +40,18 @@ A> https://stackoverflow.com/questions/1986896/what-is-the-difference-between-ca
4140

4241
### The value of this can never be null or undefined when a function is called. When null or undefined is supplied as the receiver to call() or apply(), the global object is used as the value for receiver instead.
4342

44-
4543
B> The apply function is used to call another function, with a given context and arguments, provided as an array. The min and max functions can take an arbitrary number of input arguments: Math.max(val1, val2, ..., valN)
4644

4745
So if we call:
4846

49-
``Math.min.apply(Math, [1,2,3,4]);``
47+
`Math.min.apply(Math, [1,2,3,4]);`
5048

5149
The apply function will execute:
5250

53-
``Math.min(1,2,3,4);``
51+
`Math.min(1,2,3,4);`
5452

5553
Note that the first parameter, the context, is not important for these functions since they are static, they will work regardless of what is passed as the context.
5654

57-
### Special note - With ES6, the equivalent code for the above is ``Math.max(...Arr)``
55+
### Special note - With ES6, the equivalent code for the above is `Math.max(...Arr)`
5856

59-
Replacing “Math” with “null” would output same output
57+
Replacing “Math” with “null” would output same output

Javascript/curried-function.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Example
2+
3+
```js
4+
const add = (x, y) => x + y
5+
add(2, 3) // => 5
6+
```
7+
8+
And now, below is the same function in curried form.
9+
10+
```js
11+
const add = x => y => x + y
12+
```
13+
14+
Same code without arrow syntax
15+
16+
```js
17+
const add = function(x) {
18+
return function(y) {
19+
return x + y
20+
}
21+
}
22+
```
23+
24+
Calling curried functions
25+
26+
So in order to use our curried function, we have to call it a bit differently …
27+
28+
add(2)(3) // returns 5
29+
30+
Focus on return
31+
32+
It might help to visualize it another way. We know that arrow functions work like this – let's pay particular attention to the return value.
33+
34+
```js
35+
const f = someParam => returnValue
36+
```
37+
38+
So our add function returns a function – we can use parentheses for added clarity.
39+
40+
```js
41+
const add = x => y => x + y
42+
```
43+
44+
More than two arrow functions can be sequenced, if necessary -
45+
46+
```js
47+
const three = a => b => c => a + b + c
48+
49+
const four = a => b => c => d => a + b + c + d
50+
51+
three(1)(2)(3) // 6
52+
53+
four(1)(2)(3)(4) // 10
54+
```
55+
56+
In other words add of some number returns a function
57+
58+
#### Further Reading
59+
60+
[stackoverflow.com/questions/32782922/what-do-multiple-arrow-functions-mean-in-javascript/32784025](https://stackoverflow.com/questions/32782922/what-do-multiple-arrow-functions-mean-in-javascript/32784025)

0 commit comments

Comments
 (0)