1. The first way to create an object: first define the class and then create the object
The first way to create an object: first define the class and then create the object
function Stu (Sno, name, age) {
This.sno = Sno;
THIS.name = name;
This.age = age;
This.study = function () {
Alert ("+this.sno+" student, named "+this.name+", is studying hard, age is "+this.age");
}
}
var a = new Stu (1, ' Wang ', 23);
A.study ();
2. Second way to create objects: Use object timing to create objects
// second way to create objects: Use object timing to create objects var New Object (); = 1; = "Wang"; = all; function () { alert ("sno+" + this.), the name is "+ this. name+", is studying hard, the age of "+ this . Age); } Obj.study (); Delete Obj.name; Obj.study ();
3. Third Way to create objects: creating objects using JSON syntax
Json:javascript Object Notation
Third Way to create objects: using JSON syntax to create objects
var stu = { "sno": 1, "name": "Wang" , "age": function() { alert ("sno+" + this.), the name is "+ this. name+", is studying hard, age is " +this. age);} } Stu.study ();
07.30 JavaScript--js Three ways to create objects