Created
April 10, 2018 21:54
-
-
Save orthros/7732015506ad10d23fd3baa24dc4fd28 to your computer and use it in GitHub Desktop.
Quick example of composing objects (and functions in Javascript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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