New Document
<script> <BR>//定义一个打印函数 <BR>var $=function(str){ <BR>document.write(str); <BR>document.write("<br/>"); <BR>} <BR>//定义打印数组函数 <BR>var _=function(arr){ <BR>for(var tmp in arr) <BR>{ <BR>$(arr[tmp]); <BR>} <BR>} <BR>//定义一个学生对象 <BR>var stu=new Object(); <br><br>//声明属性和行为 <BR>stu.id=16; <BR>stu.name='灯币'; <BR>stu.age=function(){ <BR>return this.id; <BR>} <br><br>//打印学生的信息 <BR>$(stu.id); <BR>$(stu.name); <BR>$(stu.age());//调用时要加括号 <br><br>stu.sex='女'; //添加新属性 <BR>$(stu.sex); //打印新添加的属性 <br><br>//方案2: <BR>function Student(id,name) <BR>{ <BR>this.id=id; <BR>this.name=name; <BR>this.getAge=function(){ <BR>return this.id; <BR>} <br><br>} <br><br>//使用 <BR>var stu2=new Student(1,'扬顿'); <BR>$(stu2.id); <BR>$(stu2.name); <BR>$(stu2.getAge()); <BR>//再定义一个属性 <BR>stu2.sex='伪娘'; <BR>$(stu2.sex); <BR>//动态语言如何跨域? <BR>Student.prototype.address="阿富汗"; <BR>$(stu2.address); <BR>$("stu2_1 begin..."); <BR>var stu2_1 =new Student(1,'扬顿'); <BR>$(stu2_1.id); <BR>$(stu2_1.name); <BR>$(stu2_1.getAge()); <BR>$(stu2_1.sex); <BR>$(stu2_1.address); //跨域访问,b对象访问a对象的属性 <BR>//在定义 <BR>$("stu2_1 end..."); <br><br>//方案3:json <BR>var stu3={id:1,name:'毛炎炎',getName:function(){return this.name;}}; <BR>$(stu3.id); <BR>$(stu3.name); <BR>$(stu3.getName()); <br><br>//var stu2 <br><br>//js里面的函数很多与java里面函数同名 <BR>var str1=new String("abcd") <BR>var str2="asdf"; <BR>$(str1.indexOf('c')); <BR>$(str1.charAt(3)); <BR>$ (str2.charAt(3)); <BR>$("absdf".substring(2,4)); <br><br>var day=new Date(); <BR>$(day.getYear()); <BR>$(day.toLocaleString()); <br><br><BR>//再谈数组 <BR>var arr1=new Array(3); <BR>arr1[0]=10; <BR>arr1[1]=20; <BR>arr1[2]=3; <BR>_(arr1); <BR>arr1[3]=4; <BR>// <BR>_(arr1); <br><br>//数组2 <BR>var arr2=new Array(234,345,2354,2134,234); <BR>_(arr2); <br><br>//数组3 <BR>var arr3=new Array(); <BR>arr3[0]=10; <BR>arr3[1]=20; <BR>arr3[2]=3; <BR>_(arr3); <br><br>//数组4.推荐写法 <BR>var arr4=[]; <BR>arr4[0]=10; <BR>arr4[1]=20; <BR>arr4[2]=3; <BR>_(arr4); <br><br>//数组5.推荐写法 <BR>var arr5=[3254,43,532,45,2345]; <BR>_(arr5); <br><br>function add(i,j){ <BR>return i+j; <BR>} <br><br>function add(i,j,k){ <BR>return i+j+k; <BR>} <br><br>$(add(1,2));//参数个数自动识别 <br><br>var Person=function(id,name) <BR>{ <BR>this.id=id;//public <BR>this.name=name;//public <BR>var i=1;//private <BR>function test(){//private <BR>alert('asdf'); <BR>} <BR>this.t=function()//public <BR>{ <BR>return 1; <BR>} <BR>} <BR>var p=new Person(1,"陈新"); <BR>$(p.id); <BR>$(p.name); <BR>$(p.t());//正常访问 <BR>$(p.test()); //不能访问 <BR></script>
Kenyataan:Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn