In JavaScript, objects are data that owns properties and methods, which are values associated with an object, by actions that can be performed on an object. JavaScript implements object-oriented programming in a way called prototypes. (Object-oriented is only a concept or a programming idea, it does not depend on a language exists.) )
First, create the object
1. Built-in objects: Common string, Date, Array, Boolean, Math, REGEXP
2. Custom Objects
01. Creating objects based on object objects
The Var object name =new an object (); (an object was created)
The object name. Property name = "attribute value"; (add attribute to object)
The name of the object. Method Name =function () {JavaScript statement} (Add method to object)
02. Literal value Assignment method
var object name ={Property Name 1: Property value 1, property Name 2: Property value 2, Method name: function () {JavaScript statement}} (note the attribute name and attribute value are separated by a colon, and multiple attributes are in comma--json format)
Second, the structure function
The so-called "constructor" is a normal function, but the this variable is used internally, and the new operator is used on the constructor to generate the instance, and the this variable is bound to the instance object
function Flower (name,genera,area,use) { this. name=name; this. genera= genera; this. area= area; this. use=uses; this. showname=showname;} function ShowName () { alert (this. name);}
JavaScript objects and knowledge-oriented objects