草庐IT

DoSomeThingWithName

全部标签

node.js - 从不同的包实现接口(interface)(从其他模块回调)

在NodeJS中,我可以在一个地方声明一个回调并在一个地方使用它,以避免破坏项目的结构。A.jsmodule.exports=classA(){constructor(name,callback){this.name=name;this.callback=callback;}doSomeThingWithName(name){this.name=name;if(this.callback){this.callback();}}}B.jsconstA=require(./A);newA=newA("KimKim",()=>console.log("SayOyeah!"));在Go中,我也