Home > Web Front-end > JS Tutorial > body text

Node.js publish-subscribe mode method

一个新手
Release: 2017-09-29 10:08:20
Original
1925 people have browsed it


//导入内置模块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('失恋');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!