我有那个代码:
function defineProperty(object, name, callback){
if(object.prototype){
Object.defineProperty(object.prototype, name, {"get": callback});
}
}
defineProperty(String, "isEmpty", function(){return this.length === 0;});
Run Code Online (Sandbox Code Playgroud)
我用它如下:
console.log("".isEmpty, "abc".isEmpty);
Run Code Online (Sandbox Code Playgroud)
它返回:
true, false
Run Code Online (Sandbox Code Playgroud)
现在,我想将函数更改为以下内容:
defineProperty(String, "isEmptyWithArrow", () => this.length === 0);
Run Code Online (Sandbox Code Playgroud)
但"这个"指的是Window,我不知道如何改变它.
当被问到这个问题时,我有一个问题要完成我的例子.
我搜索了在Google中实施IPC的方法.
我无法决定哪种方式最适合编写我的程序.
我尝试了很多实现,并且有很多并发症.
我希望:
1.管理子进程的父进程 - OK(模板)
2 .父进程和子进程必须实现新消息信号的回调
3.一个进程不知道来自其他进程的消息大小(char*)
我的代码:
header.h:
#ifndef MESSAGES_H
#define MESSAGES_H
#include <stdio.h>
#include <stdlib.h>
// need here: some includes and definitions
inline char * read_message( /* need here: some params */ ) {
// need here: read message function
}
inline char * send_message( /* need here: some params */ ) {
// need here: send message function
}
#endif
Run Code Online (Sandbox Code Playgroud)
parent.c:
#include "header.h"
// parent specyfic includes and definitions
void on_message( …Run Code Online (Sandbox Code Playgroud)