// This example is from the book _JavaScript: The Definitive Guide_. // Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. // This example is provided WITHOUT WARRANTY either expressed or implied. // You may study, use, modify, and distribute it for any purpose. // Define a constructor method for our class. // Use it to initialize properties that will be different for // each individual circle object. function Circle(x, y, r) { this.x =index.html x; // the X coordinate of the center of the circle this.y = y; // the Y coordinate of the center of the circle this.r = r; // the radius of the circle } // Create and discard an initial Circle object. // Doing this forces the prototype object to be created new Circle(0,0,0); // Now define a constant; a property that will be shared by // all circle objects. Actually, we could just use Math.PI, // but we do it this way for the sake of example. Circle.prototype.pi = 3.14159; // Now define some functions that perform computations on circles // Note the use of the constant defined above function Circle_circumference() { return 2 * this.pi * this.r; } function Circle_area() { return this.pi * this.r * this.r; } // Make these functions into methods of all Circle objects by // setting them as properties of the prototype object. Circle.prototype.circumference = Circle_circumference; Circle.prototype.area = Circle_area; // Now define a default property. Most Circle objects will share this // default value, but some may override it by setting creating their // own unshared copy of the property. Circle.prototype.url = "images/default_circle.gif"; // Now, create a circle object, and use the methods defined // by the prototype object c = new Circle(0.0, 0.0, 1.0); a = c.area(); p = c.circumference();
file: /Techref/language/JAVA/script/definitive/examples/7.4.txt, 1KB, , updated: 1997/4/4 10:59, local time: 2024/11/27 06:24,
3.149.237.231:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/Techref/language/JAVA/script/definitive/examples/7.4.txt"> language JAVA script definitive examples 7</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.