}
this.toString = function () {
return "Point(" + this.x + ", " + this.y + ")";
}
// 注意:initialize 和 toString 方法只有定义成公有成员才生效
this.add = function() {
// 调用静态方法,使用构造函数传入的 $class
return $class.add(this.x, this.y);
}
}
ZPoint.construct = function($self, $class) {
this.z = 0; // this.x, this.y 继承自 Point
// 重载 Point 的初始化函数
this.initialize = function (x, y, z) {
this.z = z;
// 调用第一个父类的初始化函数,
// 第二个父类是 $self.super1,如此类推。
// 注意:这里使用的是构造函数传入的 $self 变量
$self.super0.initialize.call(this, x, y);
// 调用父类的任何方法都可以使用这种方式,但只限于父类的公有方法
}
// 重载 Point 的 toString 方法
this.toString = function () {
return "Point(" + this.x + ", " + this.y +
", " + this.z + ")";
}
}
// 连写技巧
Class.create().register("Modello.Point").construct = function($self, $class) {
// ...
}
7,创建类的实例
// 两种方法:new 和 create
point = new Point(1, 2);
point = Point.create(1, 2);
point = Class.get("Modello.Point").create(1, 2);
zpoint = new ZPoint(1, 2, 3);
8,类型鉴别
ZPoint.subclassOf(Point); // 返回 true
point.instanceOf(Point); // 返回 true
point.isA(Point); // 返回 true
zpoint.isA(Point); // 返回 true
zpoint.instanceOf(Point); // 返回 false










