How objects in js are declared and some usage examples for arrays
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title> New Document </title><meta name="Generator" content="EditPlus"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""><script>//Define a print functionvar $=function(str){document.write(str);document.write("<br/>");}//Defines the print array functionvar _=function(arr){for(var tmp in arr){$(arr[tmp]);}}//Define a student objectvar stu=new Object();//Declare properties and behaviorsstu.id=16;stu.name=' Light currency ';stu.age=function(){return this.id;}//Print student information$(stu.id);$(stu.name);$(stu.age());//Call with parenthesesstu.sex=' female '; //Add a new property$(stu.sex); //Print the newly added properties//Scheme 2:function Student(id,name){this.id=id;this.name=name;this.getAge=function(){return this.id;}}// usevar stu2=new Student(1,' Yang, ');$(stu2.id);$(stu2.name);$(stu2.getAge());//Define one more propertystu2.sex=' transsexuals ';$(stu2.sex);//How do dynamic languages cross domains?Student.prototype.address=" Afghanistan ";$(stu2.address);$("stu2_1 begin...");var stu2_1 =new Student(1,' Yang, ');$(stu2_1.id);$(stu2_1.name);$(stu2_1.getAge());$(stu2_1.sex);$(stu2_1.address); //Cross-domain access, b objects access the properties of a objects//In the definition$("stu2_1 end...");//Scenario 3: jsonvar stu3={id:1,name:' Mao Yanyan ',getName:function(){return this.name;}};$(stu3.id);$(stu3.name);$(stu3.getName());//var stu2//Many functions in js have the same name as functions in Javavar str1=new String("abcd")var str2="asdf";$(str1.indexOf('c'));$(str1.charAt(3));$ (str2.charAt(3));$("absdf".substring(2,4));var day=new Date();$(day.getYear());$(day.toLocaleString());//Talk about an arrayvar arr1=new Array(3);arr1[0]=10;arr1[1]=20;arr1[2]=3;_(arr1);arr1[3]=4;//_(arr1);//An array of 2var arr2=new Array(234,345,2354,2134,234);_(arr2);//An array of 3var arr3=new Array();arr3[0]=10;arr3[1]=20;arr3[2]=3;_(arr3);//Array 4. Recommended writingvar arr4=[];arr4[0]=10;arr4[1]=20;arr4[2]=3;_(arr4);//Array 5. Recommended writingvar arr5=[3254,43,532,45,2345];_(arr5);function add(i,j){return i+j;}function add(i,j,k){return i+j+k;}$(add(1,2));//Automatically identify the number of parametersvar Person=function(id,name){this.id=id;//publicthis.name=name;//publicvar i=1;//privatefunction test(){//privatealert('asdf');}this.t=function()//public{return 1;}}var p=new Person(1," Chen xin ");$(p.id);$(p.name);$(p.t());//Normal access$(p.test()); //Can not access</script></head><body></body></html>