Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 22, 2017 21:54
Show Gist options
  • Save prof3ssorSt3v3/94dbe740ee8cd0c0334ecb029170abb0 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/94dbe740ee8cd0c0334ecb029170abb0 to your computer and use it in GitHub Desktop.
// 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