Skip to content

Instantly share code, notes, and snippets.

@cobbdb
Created November 5, 2014 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobbdb/bcab1dd94ac945dc4741 to your computer and use it in GitHub Desktop.
Save cobbdb/bcab1dd94ac945dc4741 to your computer and use it in GitHub Desktop.
BaseClass interface notes
var BaseClass = require('baseclassjs');
return BaseClass({
speak: BaseClass.Abstract
});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Pet = requre('./pet.js'),
Carnivor = require('./carnivor.js'),
Friendly = require('./friendly.js');
return Pet().extend({
speak: function () {
return 'woof';
}
}).implement(
Carnivor,
Friendly
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var BaseClass = require('baseclassjs');
return BaseClass.Interface({
eat: function (food) {
return 'yummy';
}
});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BaseClass.Interface = function (child) {
return function (root) {
var key;
for (key in child) {
root[key] = child[key];
}
return root;
};
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root.implement = function () {
arguments.forEach(function (module) {
module(root);
});
return root;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment