// asynchronous constructor example, // like always do not explictly return anything from the constructor function Queue(){ this.ready = false; let callable = true; let ee = new EE(); // new event emitter // the init method represents our real constructor this.init = function (){ if(this.ready){ return simpleSyncObservable(); } if(!callable){ // we already called the init method, but aren't yet ready return simpleEventObservable(ee); } callable = false; // we only want to invoke the below chain once // whichever method calls it first return someObservable() .do(() => { this.ready = true; ee.emit('ready'); }); } } // every method will probably need to call init() first before anything Queue.prototype.obs7 = function(){ // most of our methods start with init() return this.init() .mapTo(() => 7); };