By not using semicolons the code does not transpile well
I usually write javascript with semicolon but I wanted to compile this code without the use of semicolons, which I can with babel, but buble generates an error when instantiating the transpilated function
class Dispatcher{
constructor(notify=[],mdd=[]){
this.notify = notify
this.middleware(...mdd)
}
subscribe(callback){
if( typeof callback === 'function' ){
this.notify.push(callback)
return ()=>this.unsubscribe(callback)
}else{
throw new Error('Expected the subscriber to be a function')
}
}
unsubscribe(callback){
this.notify.splice(
callback,
this.notify.indexOf(callback)>>>0,1
)
}
middleware(...mdd){
}
}
Is not the complete code, but it is the perspiration that generated the error by not using a semicolon
var Dispatcher = function Dispatcher(notify,mdd){
if ( notify === void 0 ) notify=[];
if ( mdd === void 0 ) mdd=[];
this.notify = notify
(ref = this).middleware.apply(ref, mdd)
var ref;
};
Dispatcher.prototype.subscribe = function subscribe (callback){
var this$1 = this;
if( typeof callback === 'function' ){
this.notify.push(callback)
return function (){ return this$1.unsubscribe(callback); }
}else{
throw new Error('Expected the subscriber to be a function')
}
};
Dispatcher.prototype.unsubscribe = function unsubscribe (callback){
this.notify.splice(
callback,
this.notify.indexOf(callback)>>>0,1
)
};
Dispatcher.prototype.middleware = function middleware (){
var mdd = [], len = arguments.length;
while ( len-- ) mdd[ len ] = arguments[ len ];
};
You can run the lower script in the browser console to verify the transpilation error when instantiating the Dispatcher class
Made it clear that the code transpires well when using semicolons
Edited by username-removed-1481862