I have built a Constructor and added 3 functions to its prototype. When I try to call a function from the prototype i get this error
TypeError: undefined is not a function (evaluating 'fireOne.addLogs(8)')
Please can someone tell me what I am doing wrong. I cannot figure it out.
Thanks in advance
function SignalFire(ID, startingLogs){
this.fireID = ID;
this.logsLeft = startingLogs;
}
var fireOne = new SignalFire(1, 20);
var fireTwo = new SignalFire(2, 18);
var fireThree = new SignalFire(3, 24);
SignalFire.prototype = {
addLogs: function(numLogs){
this.logsLeft += numLogs;
},
lightFire: function(){
alert("Whoooooosh!");
},
smokeSignal: function(message) {
if (this.logsLeft < this.message.length / 10){
alert("Not enough fuel to send " +
"the current message!");
}
else {
this.lightFire();
var x = this.message.length;
for(var i = 0; i < x; i++){
alert("(((" + this.message[i] + ")))");
if (i % 10 === 0 && i !== 0){
this.logsLeft--;
}
}
}
}
};
fireOne.addLogs(8);
SignalFire.prototype.addLogs = function ...). But since you're outright replacing the entireprototypeobject, the reference is broken.