ooobject
Version:
object generation helper via composition, OLOO style
47 lines (31 loc) • 887 B
JavaScript
var ooobject = require('../../../index');
var obj = {
//all functions and properties starting with _ don't get enumerated
//readonly, see line 42
_nothingBroken: true,
//used for the built-in toString() function
className: 'Legs',
legsAmount: 2,
//all functions and properties starting with _ don't get enumerated
_canWalk: function(){
return this._nothingBroken;
},
walk: function(){
if(this._canWalk()){
console.log('walking with', this.legsAmount, 'legs');
}else{
console.log('can\'t walk right now');
}
}
};
//pass data and init params, needed for composition
module.exports = function Legs(data, init){
//pass in both params and init (init is needed for composition)
return ooobject.create(obj, {
data: data,
init: init,
//set _isHealthy to readonly
readonly: ['_isHealthy']
});
}
;