First, Introduction
In JS, everything is the object. strings, arrays, functions, and so on are all objects.
Second, the common JS function
/** * Display object's property method one * @returns */function myFunction1 () {person = {firstname: "David", LastName: "Smith", Age:30,sex: ' Male '};// Each is a new object, the property value can not be fixed//person2 ={...}; Printinfo (person);} /** * Display object's Properties method two */function MyFunction2 () {person = new Object ();p erson.firstname = "David";p erson.lastname = "Smith"; Person.age = 30;person.sex = ' Male ';p rintinfo (person);} /** * constructor * @returns */function person (firstname,lastname,age,sex) {this.firstname = Firstname;this.lastname= lastname; This.age = Age;this.sex = Sex;this.test = test2;//This must not be less function test2 () {document.write ("Call the person's Test ()");//alert ( "Call the person's Test ()");}} /** * Display object's property method three */function MyFunction3 () {var p = new Person ("David", "Smith", 30, ' male ');//p.test ();////printinfo (P);} /** * Traverse the property of the Person object */function Traversalperson () {//If you want to traverse this, you cannot use the constructor to create the object, var p = {firstname: "David", LastName: "Smith" , Age:30,sex: ' Male '};var str= ", var x;for (x in P) {str + = p[x]+", ";//js with" + = ", php with". = "}//document.write (str); document.getElementById ("Div1"). Innerhtml=str;} /******************** General Method ******************************//** * Output character information */function Printinfo (person) {document.getElementById ("Div1"). Innerhtml= "Name:" + person.firstname + "+ Person.lastname +", Age: "+person.age+", Gender: "+ person.sex;}
JS (i) Basic knowledge and objects