Function Factories

- function that returns or makes other thing for me

Eg:

//Instead of passing language to the outer function, so the language will be trapped in the clojure 
function makeGreeting(language){
    return function(firstname, lastname){
        if(language === 'en'){
            console.log('Hello' + firstname + lastname)
        }
        if(language === 'es'){
            console.log('Hola' + firstname + lastname)
        }        
    }

}

var greetEnglish = makeGreeting('en'); //One Execution context here
var greetSpanish = makeGreeting('es'); //Another Execution context here 
greetEnglish('John','Doe'); - Using clojure for 'es'
greetSpanish('John','Doe');

results matching ""

    No results matching ""