js学习笔记之一

时间:2023-03-09 03:04:45
js学习笔记之一

js学习笔记之一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); 
   }