You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minimalist version i coded for scratch coders like me lmao.
classEmitter{constructor(){this.eventsNames={}this.on=(callName,callback_f)=>{if(typeofcallback_f!='function')thrownewError("Callback must must type of 'function'.")if(this.eventsNames[callName]==undefined)this.eventsNames[callName]=[]this.eventsNames[callName].push(callback_f)}this.emit=(callName,datas)=>{if(this.eventsNames[callName]==undefined)return;for(letiinthis.eventsNames[callName]){try{this.eventsNames[callName][i](datas)}catch(e){console.log(e)}}}this.removeListeners=(callName)=>(this.eventsNames[callName]=[])this.removeAllListeners=(callName)=>(this.eventsNames={})this.countListeners=(callName)=>(this.eventsNames[callName]!=undefined ? this.eventsNames[callName].length : 0)}}letemitter=newEmitter()emitter.on("hello",()=>{console.log("hello world")})emitter.emit("hello")
The text was updated successfully, but these errors were encountered:
Minimalist version i coded for scratch coders like me lmao.
The text was updated successfully, but these errors were encountered: