您好,欢迎访问一九零五行业门户网

JavaScript使用prototype定义对象类型(转)[_javascript技巧

from: javaeye.com
prototype提供了一套javascript面向对象基础设施,我们可以使用它来进行面向对象编程,定义对象类型方式如下:
var person = class.create();
person.prototype = {
 initialize : function(name, age) {
 this.name = name;
 this.age = age;
 },
 tostring : function() {
 document.writeln([name]:+this.name+
+[age]:+this.age);
 }
}
先使用class.create()来创建一个对象类型,然后定义该对象类型,注意initialize方法是person的构造器,完整的html如下:
test object
其它类似信息

推荐信息