Home >Web Front-end >JS Tutorial >Node.js publish-subscribe mode method

Node.js publish-subscribe mode method

一个新手
一个新手Original
2017-09-29 10:08:201990browse


//导入内置模块let EventEmitter = require('events');
let util=require('util');//Man继承EventEmitterutil.inherits(Man,EventEmitter); 
//创建一个函数function Man(){}//实例化函数let man=new Man();function findGirl() {
    console.log('找新的女朋友')
}function saveMoney() {
    console.log('省钱')
}
man.on('失恋',findGirl)//失恋 ,绑定一个函数方法man.on('失恋',saveMoney)//失恋 ,绑定一个函数方法man.removeListener('失恋',findGirl); //移除省钱man.emit('失恋');

The above is the detailed content of Node.js publish-subscribe mode method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn