Sunday, December 4, 2016

Node.js Tutorial for Beginners 10 - Node.js Events and EventEmitter






var events = require('events');
var util = require('util');


var Students = function(name) {
    this.name = name;
}

util.inherits(Students, events.EventEmitter);

var max = new Students('max');

max.on('scored', function(marks) {
   console.log(max.name + ' scores '+ marks+ ' marks');
})

max.emit('scored', 95);

var tom = new Students('tom');

tom.on('scored', function(marks) {
   console.log(tom.name + ' scores '+ marks+ ' marks');
})

tom.emit('scored', 60);

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Stuff I use to make videos

Windows notebook - http://amzn.to/2ADOPrW

Apple MacBook Pro - http://amzn.to/2AC0WG2

Microphone - http://amzn.to/2AC1kV0

notebook mouse - http://amzn.to/2BmeZ2d