在javaScript中创建新对象: 定义对象 创建实例
1.定义对象
function University( name, city, createDate, URL )
this.name = name;
this.city = city;
this.createDate = new Date(createDate)
this.URL = URL;
2.创建实例
University univ = new University("tianjin", "tianjin province", "1895-10-02",
"http://www.tju.edu.cn");
3.使用对像的方法
function University( name, city, createDate, URL)
{
this.name ="Tianjin University";
this.city = "Tianjin";
this.createDate = "1895-10-02";
this.URL = "
http://www.tju.edu.cn";
this.showUniversity = showUniversity;/**定义对象中的方法 this.meth=FunctionName语句*/
}
定义了一个方法: showUnversity()
function showUniversity()
{
for(var propertity in this)
alert(propertity += this[propertity] + " ");