Skip to content

Instantly share code, notes, and snippets.

@miksansegundo
Last active December 23, 2015 20:59
Show Gist options
  • Save miksansegundo/099590070726375761e6 to your computer and use it in GitHub Desktop.
Save miksansegundo/099590070726375761e6 to your computer and use it in GitHub Desktop.
// 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