You just need to return the function from your createFunction
function createFunction(){
return function myFunction(){console.log('Hello World!');};
};
var myFunction = createFunction();
myFunction() // => Hello World!, You just learn't functional js
with functional js you can also use currying to pass in parameters to make functions more re-usable eg.
function createFunction( greeting ){
return function myFunction( who ){console.log( greeting + ' ' + who );};
};
// create two functions from our createFunction and return some partially applied functions.
var hello = createFunction('Hello'); // => myFunction with greeting set
var sup = createFunction('Sup'); // myFunction with greeting set
// now that functions hello and sup have been created use them
hello('World!') // => Hello World!
hello('Internets!') // => Hello Internets!
sup('Stack!') // => Sup Stack!
sup('Functional JS!') // => Sup Functional JS!