node03-events

目录:node01-创建服务器
node02-util
node03-events
node04-buffer
node05-fs
node06-path
node07-http
node08-express
node09-cookie

events模块:

 1 // var events = require("events").EventEmitter();//老式写法
 2 var events = require("events");
 3 var util = require("util");
 4 function Goddess(){
 5     //女神类,会触发一些事件,比如饿了
 6 }
 7 function Boy(name,response){
 8     this.name = name;
 9     this.response = response;
10 }
11 util.inherits(Goddess,events);//继承事件的各种方法和属性
12
13 var girl = new Goddess();
14 var boy1 = new Boy("备胎1",function(){
15    console.log("吃鸡腿");
16 });
17 var boy2 = new Boy("备胎2",function(){
18     console.log("吃牛排");
19 });
20
21
22 girl.setMaxListeners(3);//设置最大事件数
23 //添加事件
24 girl.on("ele",boy1.response);
25 girl.addListener("ele",function(){
26     console.log("自己做点吃的");
27 });
28 girl.on("ele",boy2.response);
29 girl.once("die",function(){
30     console.log("死了");
31 });
32 // girl.removeListener("ele",boy1.response);//移除事件
33 girl.removeAllListeners("ele");//移除ele
34 //发射事件
35 girl.emit("ele");
36 girl.emit("die");
37 girl.emit("ele");
38 girl.emit("die");
时间: 2024-11-06 03:57:59

node03-events的相关文章

Threads Events QObjects

Events and the event loop Being an event-driven toolkit, events and event delivery play a central role in Qt architecture. In this article we'll not give a comprehensive coverage about this topic; we'll instead focus on some thread-related key concep

TI C66x DSP 系统events及其应用 - 5.3(Interrupt)

对于TI C66x DSP的每个CPU有INT4~15共12个中断输入.对于中断,event combiner将INTC的输入event 4~127分为4个组(event 0~3为INTC内部使用,如图示为event combiner的四个输出),然后event 0~127作为Interrupt Selector的输入.类似于4.x中的exception,中断也有同样功能的event flag,event mask,masked event flag寄存器. Interrupt Seclctor

[Vue + TS] Using Route events inside Vue

vue-router introduces new hooks into the component. In this lesson we’ll show you how to use these new hooks in your class based Vue components in TypeScript. We’ll also go over how we can create and use routes in Vue. Default component: <template>

npm run dev报错,events.js:160 throw er; // Unhandled &#39;error&#39; event

错误代码如下: [email protected] dev E:MySoftwaretestGitwebpackvue-projectnode build/dev-server.js "8088" events.js:160 throw er; // Unhandled 'error' event ^ Error: listen EACCES 0.0.0.0:8080 at Object.exports._errnoException (util.js:1026:11) at expo

R语言:SMOTE - Supersampling Rare Events in R:用R对非平衡数据的处理方法

SMOTE - Supersampling Rare Events in R:用R对稀有事件进行超级采样 在这个例子中将用到以下三个包 {DMwR} - Functions and data for the book "Data Mining with R" and SMOTE algorithm:SMOTE算法 {caret} - modeling wrapper, functions, commands:模型封装.函数.命令 {pROC} - Area Under the Curv

bzoj1664[Usaco2006 Open]County Fair Events 参加节日庆祝*

bzoj1664[Usaco2006 Open]County Fair Events 参加节日庆祝 题意: 有N个节日,每个节日有个开始时间,及持续时间.牛想尽可能多的参加节日,问最多可以参加多少.注意牛的转移速度是极快的,不花时间,且节日必须完整参加.N≤10000,开始时刻和持续时间≤100000. 题解: dp.设f[i]表示i时刻到最后时刻最多可以参加多少节日.则f[i]=max(f[i+1],f[range[j].r+1],j为时刻i开始的节日). 代码: 1 #include <cs

[Repost]Events and Signals in PyQt4

Reference:http://zetcode.com/gui/pyqt4/eventsandsignals/ Events and Signals in PyQt4 In this part of the PyQt4 programming tutorial, we will explore events and signals occurring in applications. Events All GUI applications are event-driven. Events ar

SQL Server Extended Events 进阶 1:从SQL Trace 到Extended Events

http://www.sqlservercentral.com/articles/Stairway+Series/134869/ SQL server 2008 中引入了Extended Events 用以替换SQL Trace. 然而在第一个版本中并没有为用户提供UI,因此使用Extended Events并不是很方便.SQL Server 2012及时修正了这一点,将UI管理工具集成在SSMS中, 这就意味着我们不需要再为了查询Event XML而学习使用XQuery了.因此跟多的DBA和开

events.js:72 throw er; // Unhandled &#39;error&#39; event

http://stackoverflow.com/questions/24525253/events-js72-throw-er-unhandled-error-event 出现了一个上述的错误. events.js:72 throw er; // Unhandled 'error' event 于是谷歌之后发现是已经打开了一个监听. 于是把那个关闭了就可以了 events.js:72 throw er; // Unhandled 'error' event

Events

To create real interactivity on a website, you need events — these are code structures that listen out for things happening to the browser, and then allow you to run code in response to those things. The most obvious example is the click event, which