Created
November 27, 2012 17:48
-
-
Save jesgundy/4155834 to your computer and use it in GitHub Desktop.
Prototypal inheritance example
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
// Prototype Example | |
var Example = function(a, b) { | |
this.product = this.mult(a, b); | |
this.power = this.pow(a, b); | |
}; | |
Example.prototype = { | |
mult: function(a, b) { | |
return a * b; | |
}, | |
pow: function(num, pow) { | |
var n = num; | |
while (pow -= 1) n = this.mult(n, num); | |
return n; | |
} | |
}; | |
var demo = new Example(2, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment