ooobject
Version:
object generation helper via composition, OLOO style
48 lines (32 loc) • 926 B
JavaScript
var ooobject = require('../../../index');
var obj = {
//all functions and properties starting with _ don't get enumerated
//readonly, see line 43
_underWater: false,
lungColor: 'white',
//used for the built-in toString() function
className: 'Lungs',
lungsAmount: 2,
//all functions and properties starting with _ don't get enumerated
_canBreath: function(){
return !this._underWater;
},
breathe: function(){
if(this._canBreath()){
console.log('breathing with', this.lungsAmount, 'lungs');
}else{
console.log('can\'t breathe');
}
}
};
//pass data and init params, needed for composition
module.exports = function Lungs(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: ['_underWater', 'lungColor']
});
}
;