The code is very simple, so there is no more nonsense.
The code copy is as follows:
//The first way to define
var person=new Object(); //A object was created.
person.name="tom"; //Call the name attribute using the person object pair, and its value is tom
alert(person.name); //Show name attribute value
person.say=function(){ //Add a say function to the person object.
alert("person says");
};
person.say();
The code copy is as follows:
//The second way of definition
var person={
name:"tom",
say:function(){
alert("hello person");
}
}; //A object was created.
//alert(person.name);
//person.say();
person.age=10;
alert(person.age);
//The class defined in js is to use function.
var Person = function(name){ //We are defining a class. It is equivalent to having a constructor with parameters.
this.name =name;//Properties of class
this.say = function(){ //Method of class.
alert("say good");
}
}
var p = new Person("fox"); //Define an object p of the Person class
alert(p.name); //Calling name attribute