The code is very simple, it is not a lot of nonsense.
Copy Code code as follows:
The first way of defining
var person=new Object (); An object was created.
Person.name= "Tom"; Call the Name property with the person object, and its value is Tom
alert (person.name); Show Name property value
Person.say=function () {//Adds a say function to the person object.
Alert ("person say");
};
Person.say ();
Copy Code code as follows:
The second way of defining
var person={
Name: "Tom",
Say:function () {
Alert ("Hello person");
}
}; An object was created.
alert (person.name);
Person.say ();
person.age=10;
alert (person.age);
The class defined in JS is the use function.
var person = function (name) {//We are defining a class. It is equivalent to having a constructor with parameters.
Properties of the THIS.name =name;//class
This.say = Method of the function () {//class.
Alert ("Say good");
}
}
var p = new Person ("fox"); Define an object p for the person class
alert (p.name); Call the Name property