Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Last active January 28, 2018 12:39
Show Gist options
  • Save tournasdim/8ab3dbec6a3ada0a92021369104b71c9 to your computer and use it in GitHub Desktop.
Save tournasdim/8ab3dbec6a3ada0a92021369104b71c9 to your computer and use it in GitHub Desktop.
#nodejs Enclosure . Fun Facts : Being that enclosures have access to their outer functions variables and parameters, this allows the enclosures to be called later after the function returns and still be able to have access to these variables.
// Reference : JavaScript for Experienced Developers
// https://www.youtube.com/watch?v=h50lRx3Myfo&list=PLknneukDQdN9sz45rtMkT3k0uq36d7rGj&index=141 (min 17:00)
function setFirstname(firstname) {
function appendLastName (lastname) {
console.log("My fullName is : " + firstname + " " + lastname );
};
return appendName;
}
var combineMyname = setFirstname("Tournas");
combineMyname("Dimitrios") ;
// Result:
/*
root@root:/tmp/playground$ node test.js
My fullName is : Tournas Dimitrios
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment