01.js

来自「进行ajax开发sdsd s d sd s」· JavaScript 代码 · 共 27 行

JS
27
字号
// We begin with the constructorfunction Circle(radius) {    // r is an instance property, defined and initialized in the constructor.    this.r = radius;}// Circle.PI is a class property--it is a property of the constructor function.Circle.PI = 3.14159;// Here is an instance method that computes a circle's area.Circle.prototype.area = function() { return Circle.PI * this.r * this.r; }// This class method takes two Circle objects and returns the// one that has the larger radius.Circle.max = function(a,b) {    if (a.r > b.r) return a;    else return b;}// Here is some code that uses each of these fields:var c = new Circle(1.0);      // Create an instance of the Circle classc.r = 2.2;                    // Set the r instance propertyvar a = c.area();             // Invoke the area() instance methodvar x = Math.exp(Circle.PI);  // Use the PI class property in our own computationvar d = new Circle(1.2);      // Create another Circle instancevar bigger = Circle.max(c,d); // Use the max() class method

⌨️ 快捷键说明

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