Skip to content

Instantly share code, notes, and snippets.

@actaneon
Created July 8, 2009 20:23
Show Gist options
  • Save actaneon/143157 to your computer and use it in GitHub Desktop.
Save actaneon/143157 to your computer and use it in GitHub Desktop.
Javascript Prototype Example
<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