Main File
var DogModule = require('Dog');
var dogsList = [];
function addNewDog(){
var newDog = new Dog();
dogsList.push(newDog);
}
???.on('bark', function(barkSound) {
console.log(barkSound);
});
Dog File
var EventEmitter = require('events').EventEmitter;
function Dog() {
EventEmitter.call(this);
this.name = "asda";
this.chipId = 1234;
this.emit('bark', "au-au");
}
Dog.prototype = {
getName: function () {
return this.name;
},
getChipId: function () {
return this.chipId;
}
}
Question 1 - How can i properly add EventEmitter.prototype to Dog object and save the current prototype and basically just get access to EventEmitter methods?
- Dog.prototype = Object.create(EventEmitter.prototype);
- Using util module and then util.inherits(Dog, EventEmitter);
The problem here is just how to not overwrite the existing methods...
Question 2 - Handle one object its no problem but for multiple how i can handle them individuality, knowing that they will be stored on that list?
Thank you.