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
//OLOO - delegated objects | |
var Animal = { | |
init: function(name) { | |
this.name = name | |
}, | |
say: function() { | |
console.log(`I am ${this.name}`) | |
} | |
} |
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
//Function inheritance | |
function Animal(name) { | |
this.name = name | |
this.say = function() { | |
console.log(`I am ${this.name}`) | |
} | |
} | |
function Rabbit(name) { |
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
//Prototype Pattern | |
function Animal(name) { | |
this.name = name | |
} | |
Animal.prototype.say = function() { | |
console.log(`I am ${this.name}`) | |
} | |
function Rabbit(name) { |
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
//Function composition | |
function Animal(name) { | |
let publicAPI = { | |
say: function() { | |
console.log(`I am ${name}`); | |
} | |
} | |
return publicAPI | |
} |
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
let observerDecorator = (function () { | |
let eventList = {} | |
return function (obj) { | |
obj.addEvent = (event, fn) => { | |
if(!eventList[event]) { | |
eventList[event] = [] | |
} | |
if(eventList[event].indexOf(fn) === -1) { |
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
(function() { | |
let chatModule = (function() { | |
let message = 'hi bro' | |
function say() { | |
console.log(message); | |
} | |
return { | |
say: say |
NewerOlder