小编s77*_*77s的帖子

JavaScript ecma6将正常功能更改为箭头功能

我有那个代码:

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,我不知道如何改变它.

我的小提琴

javascript ecmascript-6 arrow-functions

5
推荐指数
1
解决办法
780
查看次数

Linux中C语言双向IPC的最佳方式

当被问到这个问题时,我有一个问题要完成我的例子.
我搜索了在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)

c linux

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrow-functions ×1

c ×1

ecmascript-6 ×1

javascript ×1

linux ×1