事件events 是nodejs主要特性,为方便应用现举例如下,以供初学者参考;
-
var util = require("util");
-
var events = require("events");
-
-
var Test= function(){
-
events.EventEmitter.call(this);
-
this.val = 1121;
-
}
-
util.inherits(Test, events.EventEmitter);
-
-
var pro = Test.prototype;
-
pro.on('test',function(arg){
-
console.log(arg);
-
});
-
-
pro.fun = function(){
-
this.emit("test","bbbbbbbbbbbbbb");
-
}
-
-
-
var t = new Test();
-
t.fun();
阅读(2758) | 评论(0) | 转发(0) |