java语言深入编写高级jscript代码(Java language depth written high-level JScript code).docVIP

  • 2
  • 0
  • 约1.11万字
  • 约 14页
  • 2017-10-07 发布于河南
  • 举报

java语言深入编写高级jscript代码(Java language depth written high-level JScript code).doc

java语言深入编写高级jscript代码(Java language depth written high-level JScript code)

java语言深入编写高级jscript代码(Java language depth written high-level JScript code) 1, create advanced objects Use constructors to create objects A constructor is a function call to instantiate and initialize the special type of object. You can call a constructor using the new keyword. A new example of using the constructor is given below. Var myObject = new (Object); / / create a generic object has no attribute. Var myBirthday = new Date (1961, 5, 10); / / create a Date object. Var myCar = new (Car); / / create an object of a user defined, and initialize their properties. A parameter is passed to the newly created null object by the constructor as a value for a particular this keyword. The constructor then is responsible for performing adaptive initialization for the new object (creating attributes and giving their initial values). When finished, the constructor returns a parameter of the object it constructs. Write constructors You can create objects and initialize them by using the new operator in combination with predefined constructors like Object (), Date () and Function (). The powerful feature of object oriented programming is the ability to define custom constructors to create custom objects that are used in scripts. Creates a custom constructor so that you can create objects that have defined properties. Here is an example of a custom function (note the use of the this keyword). When you call the Circle constructor, give the value of the center point and the radius of the circle (all of these elements are necessary to completely define a unique round object). At the end, the Circle object contains three attributes. Here is how to instantiate a Circle object. Var aCircle = new Circle (5, 11, 99); Using prototypes to create objects When you write a constructor, you can use the properties of a prototype object, which itself is an attribute of all constructors, to create inheritance properties and share methods. The prototype properties and methods will be copied to ea

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档