UNPKG

ooobject

Version:

object generation helper via composition, OLOO style

60 lines (39 loc) 1.06 kB
'use strict'; var ooobject = require('../../index'); var Legs = require('./components/Legs'); var Lungs = require('./components/Lungs'); var obj = { //used for the built-in toString() function className: 'Component', name: 'John Doe', //readonly, see line 55 alive: true, age: 0, isPerson: true, //all functions and properties starting with _ don't get enumerated _isAlive: function(){ return this.alive; }, doYourThing: function(){ console.log(this.name, 'is:'); if(this._isAlive()){ this.walk(); this.breathe(); } }, }; //pass data and init params, needed for composition module.exports = function Person(data, init){ return ooobject.create(obj, { //components to compose this object with components: [ Legs, Lungs ], data: data, init: init, //looks for readonly props in components and merges them with props below //in this example readonly becomes ['_nothingBroken', '_underWater', 'alive', 'lungColor'] readonly : ['alive'] }); }