Created
November 5, 2014 23:23
-
-
Save cobbdb/bcab1dd94ac945dc4741 to your computer and use it in GitHub Desktop.
BaseClass interface notes
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
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