Created
August 16, 2015 13:17
-
-
Save AllanJunLi/245af202b960c8758de7 to your computer and use it in GitHub Desktop.
JavaScript class constructor
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
function Circle(radius) { | |
this.radius = radius; | |
this.area = function() { | |
return this.radius * this.radius * Math.PI; | |
}; | |
} | |
var instance = {}; | |
Circle.call(instance, 5); | |
instance.area(); | |
var instance2 = new Circle(5); | |
instance2.area(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment