Last active
August 29, 2015 14:14
-
-
Save appkr/413f37c6003016a49f91 to your computer and use it in GitHub Desktop.
JavaScript Inheritance for Performance// source http://jsbin.com/necegu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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