⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8-4.txt

📁 Javascript语言开发经典教程开发
💻 TXT
字号:
// 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 = 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.// This forces the prototype object to be created in Navigator 3.new Circle(0,0,0);// 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;// Define a method to compute the circumference of the circle.// First declare a function, then assign it to a prototype property.// Note the use of the constant defined above.function Circle_circumference() { return 2 * this.pi * this.r; }Circle.prototype.circumference = Circle_circumference;// Define another method. This time we use the Function()// constructor to define the function and assign it to a prototype// property all in one step.Circle.prototype.area = new Function("return this.pi * this.r * this.r;");// The Circle class is defined.// Now we can create an instance and invoke its methods.var c = new Circle(0.0, 0.0, 1.0);var a = c.area();var p = c.circumference();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -