Created
July 8, 2009 20:23
-
-
Save actaneon/143157 to your computer and use it in GitHub Desktop.
Javascript Prototype 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
<html> | |
<body> | |
<span id="main" /> | |
<script> | |
function Circle(radius) { | |
this.PI = 3.141592654; | |
this.radius = radius; | |
this.Diameter = function() { | |
return this.radius * 2; | |
} | |
this.Circumference = function() { | |
return this.PI * this.Diameter(); | |
} | |
} | |
Circle.prototype.Area = function() { | |
return this.PI * Math.pow(this.radius, 2); | |
} | |
var c1 = new Circle(3); | |
c1.radius = 5; | |
main.innerHTML = "" | |
main.innerHTML += "Radius: " + c1.radius; | |
main.innerHTML += "<br/>"; | |
main.innerHTML += "Diameter: " + c1.Diameter(); | |
main.innerHTML += "<br/>"; | |
main.innerHTML += "Circumference: " + c1.Circumference(); | |
main.innerHTML += "<br/>"; | |
main.innerHTML += "Area: " + c1.Area(); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment