JavaScript类和内置对象
Javascript 对象 和类
Javascript是基于对象而非面向对象的程序设计语言,它不支持类和继承,Javascript在面向对象方面与Java的严谨相比,显得非常随便。
创建对象
Javascript通过实现包含属性说明和方法定义的构造方法来声明类,并没有专门的class类定义。
如:用来声明Oven类的构造方法
function Oven(color,type,time)
{this.color=color;
this.type=type;
this.time=time;
this.info=info;
}
function info()
{document.writeln("<B>颜色:</B>",this.color);
document.writeln("<B>类型:</B>",this.type);
document.writeln("<B>出厂日期:</B>",this.time);
}
创建Oven类对象实例:
oven1=new Oven("红色","精巧型","99.1.1");
oven2=new Oven("蓝色","典雅型","99.10.1");
oven3=new Oven("黄色","实用型","2000.1.1");
jscript1.html:
<HTML>
<HEAD>
<TITLE> "欢迎选购"</TITLE>
<s cript LANGUAGE="Javas cript" >
function Oven(color,type,time)
{this.color=color;
this.type=type;
this.time=time;
this.info=info;
}
function info()
{document.writeln("<B>颜色:&l [1] [2] [3] [4] [5] [6] [7] 下一页
|