js学习笔记之一

一.Javascript 中的对象 
1、 建立自定义对象 
方法1:对象={属性1:属性值1,属性2:属性值2……属性n:属性值n} 
方法2:先定义构造函数,再new创建对象实例。 


     如: 

function car(thecolor,thenumber,thewheels) 
           { this.color=thecolor; 
             this.number=thenumber; 
             this.wheels=thewheels;  
          }

     var   mycar=new car("RED","13245",4); 

 

     注:这里的函数与面向对象稍有不同,这里的函数代表对象的构造函数-即对象
2、 定义对象的方法    
     function ReportInfo( ) 
   { var information=new string; 
     information="color:"+this.color+"<BR>"; 
     information+="Number:"+this.Number+"<BR>"; 
     information+="Wheels"+this.wheels; 
     window.document.write(information); 
   }

posted on 2016-04-24 23:53  JulyChu  阅读(170)  评论(0)    收藏  举报