Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从节点事件处理程序中调用函数_Node.js_Typescript_Events_Electron - Fatal编程技术网

Node.js 从节点事件处理程序中调用函数

Node.js 从节点事件处理程序中调用函数,node.js,typescript,events,electron,Node.js,Typescript,Events,Electron,我正在使用icpRenderer在电子应用程序中从渲染器向主进程发送消息。下面是侦听消息的处理程序。我想从该处理程序中调用另一个函数。我怎样才能把这个绑起来 constonMessageReceived=(m:string)=>{ 控制台日志(m); }; ipcMain.on('my-custom-signal',(事件,参数)=>{ this.onMessageReceived(arg);//我怎么称呼它? }); 此在处理程序中是不同的 您可以这样做: let that = this;

我正在使用icpRenderer在电子应用程序中从渲染器向主进程发送消息。下面是侦听消息的处理程序。我想从该处理程序中调用另一个函数。我怎样才能把这个绑起来

constonMessageReceived=(m:string)=>{
控制台日志(m);
};
ipcMain.on('my-custom-signal',(事件,参数)=>{
this.onMessageReceived(arg);//我怎么称呼它?
}); 

在处理程序中是不同的

您可以这样做:

let that = this;
const onMessageReceived = (m: string) => {
  console.log(m);
};

ipcMain.on('my-custom-signal', (event, arg) => {
  that.onMessageReceived(arg); // how can I call this?
});

删除
this
-与Java
等语言不同,this.something()
something()完全不同,谢谢