Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

js中成员函数如何调用自身

$
0
0
function SocketIO() {
    this.socket = null;
	this.reconnect=null
}

SocketIO.prototype.start = (server)=> {
    let self = this;
    this.socket = so(server);
	this.socket.on('connect', ()=> {
		self.waitType()
    });
    this.socket.on('disconnect', ()=> {
            self.socket = self.start(self.reconnect);
    });
};

SocketIO.prototype.waitType = ()=> {
    let self = this;
    process.stdin.setEncoding('utf8');
    process.stdin.on('readable', () => {
        let chunk = process.stdin.read();
        let cmds = chunk.trim().split(' ');
        switch (cmds[0]) {
            case 'connect':
                self.reconnect = cmds[1];
                break;
        }
    });
};

Viewing all articles
Browse latest Browse all 14821

Trending Articles