-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappEvent.js
More file actions
38 lines (30 loc) · 795 Bytes
/
Copy pathappEvent.js
File metadata and controls
38 lines (30 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const EventEmitter = require('events');
const eventEmitter = new EventEmitter();
eventEmitter.on('tutorial',(num1,num2)=>{
console.log('The tutorial event has occured!!!');
console.log(num1+num2);
});
eventEmitter.on('app',()=>{
console.log('Hello chalani!!!');
});
eventEmitter.emit('tutorial',1,4);
eventEmitter.emit('app');
class Person extends EventEmitter{
constructor(name){
super();
this._name = name;
}
get name(){
return this._name;
}
}
let padro = new Person('Chalanika');
let mahe = new Person('Maheshavee');
padro.on('name',()=>{
console.log('My name is '+ padro.name);
});
mahe.on('name',()=>{
console.log('My name is '+ mahe.name);
});
padro.emit('name');
mahe.emit('name');