Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/413f37c6003016a49f91 to your computer and use it in GitHub Desktop.
Save appkr/413f37c6003016a49f91 to your computer and use it in GitHub Desktop.
JavaScript Inheritance for Performance// source http://jsbin.com/necegu
//noprotect
function SignalFire(ID, startingLogs) {
this.fireID = ID;
this.logsLeft = startingLogs;
}
SignalFire.prototype = {
addLogs: function(numLogs) {
this.logsLeft += numLogs;
},
lightFire: function() {
alert("Woooosh!");
},
smokeSignal: function(message) {
var x = message.length;
if(this.logsLeft < (x / 10)) {
alert("Not enough fuel to send the current message!");
} else {
this.lightFire();
for(var i = 0; i < x; i++) {
alert("(((" + message[i] + ")))");
if(i % 10 === 0 && i !== 0) {
this.logsLeft--;
}
}
}
}
};
var fireOne = new SignalFire(1, 20);
var fireTwo = new SignalFire(2, 18);
var fireThree = new SignalFire(3, 24);
fireOne.addLogs(8);
fireTwo.addLogs(10);
fireThree.addLogs(4);
fireThree.smokeSignal("Goblins!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment