Skip to content

Instantly share code, notes, and snippets.

@buddy-sandidge
Last active August 29, 2015 14:05
Show Gist options
  • Save buddy-sandidge/f1a4c9a0c9a4db8b92ee to your computer and use it in GitHub Desktop.
Save buddy-sandidge/f1a4c9a0c9a4db8b92ee to your computer and use it in GitHub Desktop.
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