Skip to content

Instantly share code, notes, and snippets.

@orthros
Created April 10, 2018 21:54
Show Gist options
  • Save orthros/7732015506ad10d23fd3baa24dc4fd28 to your computer and use it in GitHub Desktop.
Save orthros/7732015506ad10d23fd3baa24dc4fd28 to your computer and use it in GitHub Desktop.
Quick example of composing objects (and functions in Javascript)
function worker(x) {
console.log("Look at me I'm calling some function");
if('someFunction' in x) {
x.someFunction();
}
else{
console.log("Wait... there's nothing here");
}
};
var someObject = {};
worker(someObject);
someObject.someFunction = function(){
console.log("I'm Mr Meeseks!");
}
worker(someObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment