Last active
August 29, 2015 14:05
-
-
Save buddy-sandidge/f1a4c9a0c9a4db8b92ee 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
function extend(base, parent) { | |
for (var prop in parent) { | |
if (!base.hasOwnProperty(prop)) { | |
base[prop] = parent[prop]; | |
} | |
} | |
} | |
function noop() {} | |
function Base() {} | |
Base.prototype = { | |
start: noop, | |
stop: noop, | |
render: noop | |
}; | |
function Widget() {} | |
Widget.prototype = { | |
render: function () { | |
console.log('rendering without needing to care about star or /stop'); | |
} | |
}; | |
extend(Widget.prototype, Base.prototype); | |
function Module(name) { | |
this.name = name || 'unknown'; | |
} | |
Module.prototype = { | |
start: function () { | |
console.log('Module "' + this.name + '" is starting'); | |
}, | |
stop: function () { | |
console.log('Module "' + this.name + '" is stopping'); | |
}, | |
}; | |
extend(Module.prototype, Base.prototype); | |
function invoke(method) { | |
return function _invoke(obj) { | |
obj[method](); | |
}; | |
} | |
function fakeFramework(items) { | |
items.forEach(invoke('start')); | |
items.forEach(invoke('render')); | |
items.forEach(invoke('stop')); | |
} | |
fakeFramework([new Widget(), new Module(), new Widget(), new Module('foo')]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment