Skip to content

Commit d412b3c

Browse files
author
ashfaq
committed
currying
1 parent da7e783 commit d412b3c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

closureCallback.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ function tellMeWhenDone(callback){
1515

1616
tellMeWhenDone(function(){console.log("I am Done")})
1717

18-
tellMeWhenDone(function(){alert("I am Done")})
18+
tellMeWhenDone(function(){alert("I am Done")})
19+
20+
21+
// Have a look a currying.js

currying.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// <input onClick={ this.handleClick({ anyValue }) } />
2+
"use strict"
3+
4+
let handleClick = ({ name }) => (e) => {
5+
console.log(name) // index or id I may want to assign value to
6+
console.log(this) // the value of the input field
7+
}
8+
9+
let a = handleClick({name: 'Ashfaq'});
10+
let b = handleClick({name: 'Ansari'});
11+
12+
console.log(a.name)
13+
console.log(a === b)
14+
15+
// In debug check the scope 3 {closure will be different}
16+
// reference to name will be different.
17+
// https://hackernoon.com/curry-away-in-react-7c4ed110c65a
18+
// https://medium.freecodecamp.org/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb

0 commit comments

Comments
 (0)