var Object = { __name__: #"Object" };
|
|
|
|
print("Object is ", Object);
|
|
|
|
var Point = { __name__: #"Point", __proto__ : Object };
|
|
|
|
print("Point is ", Point);
|
|
|
|
Object.new = fun () {
|
|
print("ARGS are ", __arguments__);
|
|
var obj= { __proto__ : this };
|
|
var init= this.init;
|
|
print("INIT is ", init);
|
|
init && invoke(obj, init, __arguments__);
|
|
obj;
|
|
};
|
|
|
|
print("Object.new is ", Object.new);
|
|
|
|
print("Point.new is ", Point.new);
|
|
|
|
print("Object.new() is ", Object.new());
|
|
|
|
Point.init = fun (x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
var p = Point.new(3, 4);
|
|
|
|
print("Point.new(3, 4) is ", p);
|
|
|
|
|
|
|
|
Object.clone = fun () { clone(this) }
|
|
|
|
var q = p.clone();
|
|
|
|
print("clone is ", q);
|
|
|
|
Object.println = fun () { this.print(); print('\n'); this; }
|
|
|
|
Object.print = fun () {
|
|
var proto= this.__proto__;
|
|
if (!proto) print(this);
|
|
else {
|
|
var name= proto.__name__;
|
|
if (!name) print(this);
|
|
else {
|
|
print(name, "{");
|
|
var keys= keys(this);
|
|
for (var i= 0; i < length(keys); ++i) {
|
|
var key= keys[i];
|
|
var val= this[key];
|
|
if (i) print(", ");
|
|
print(" ", key, ": ", val);
|
|
}
|
|
print(" }");
|
|
}
|
|
}
|
|
this;
|
|
}
|
|
|
|
p.println()
|