时间:2021-07-01 10:21:17 帮助过:5人阅读
// Define a constructor method for our class.
// Use it to initialize properties that will be different for
// each individual Circle object.
functionCircle(x, y, r)
{
this.x = x; // The X-coordinate of the center of the circle
}
// Create and discard an initial Circle object.
// This forces the prototype object to be created in JavaScript 1.1.
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 instruction.
Circle.prototype.pi =
// 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
Circle.prototype.circumference =Circle_circumference;
// Define another method. This time we use a function literal to define
// the function and assign it to a prototype property all in one step.
Circle.prototype.area =
// The Circle class is defined.
// Now we can create an instance and invoke its methods.
var c =
var a =c.area( );
var p = c.circumference( );
// Returns true if the last character is c
String.prototype.endsWith =
return (c ==
}
var message =
message.endsWith('h') // Returns false
message.endsWith('d') // Returns true