Created
July 22, 2017 21:54
-
-
Save prof3ssorSt3v3/94dbe740ee8cd0c0334ecb029170abb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function Currying | |
//In JavaScript, functions are first-class objects, | |
// just like String, Number, Boolean | |
//This means that they can be passed to functions or returned from functions | |
// | |
function greet(msg){ | |
//console.log(msg); | |
return function(name){ | |
console.log(msg, name); | |
//console.log('Hi', name); | |
} | |
} | |
let english = greet('Hi'); | |
let svenska = greet('Hej'); | |
let espanol = greet('Hola'); | |
let deutsch = greet('Tag'); | |
english('Tom'); | |
svenska('Inga'); | |
espanol('Carlos'); | |
deutsch('Mattias'); | |
/* | |
function x(a){ | |
console.log('x'); | |
a(); //will execute function y | |
return a; | |
} | |
function y(){ | |
console.log('y'); | |
} | |
let b = x(y); //calling function x | |
b(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment