Last active
December 23, 2015 20:59
-
-
Save miksansegundo/099590070726375761e6 to your computer and use it in GitHub Desktop.
This file contains 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
// Info: http://chimera.labs.oreilly.com/books/1234000000262/ch03.html#factories | |
function factory() { | |
var highlander = { | |
name: 'MacLeod' | |
}; | |
return { | |
get: function get() { | |
return highlander; | |
} | |
}; | |
} | |
// Other with composition | |
function Animal(name) { | |
//… | |
} | |
function Rabbit(name) { | |
var rabbit = Animal(name) | |
var parentRun = rabbit.run | |
rabbit.jump = function() { | |
alert(name + " jumped!") | |
} | |
rabbit.run = function() { | |
parentRun.call(this) | |
alert("fast") | |
} | |
return rabbit | |
} | |
rabbit = Rabbit("rab") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment