Skip to content

Instantly share code, notes, and snippets.

@Sljubura
Created February 12, 2013 19:26
Show Gist options
  • Save Sljubura/4772566 to your computer and use it in GitHub Desktop.
Save Sljubura/4772566 to your computer and use it in GitHub Desktop.
Self-defining functions.
// Self-defining functions
var greetings = function () {
console.log("Hello!");
greetings = function () {
console.log("Goodbye!");
}
};
greetings(); // Hello!
greetings(); // Goodbye!
// Note that if you assign 'greetings' to another variable,
// that second variable will always point to the last 'greetings' state.
var goodbye = greetings;
goodbye(); // Goodbye!
goodbye(); // Goodbye!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment