Skip to content

Instantly share code, notes, and snippets.

View vasergen's full-sized avatar

Vasyl Gendzeliuk vasergen

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