Skip to content

Instantly share code, notes, and snippets.

@stdray
Created August 13, 2014 12:09
Show Gist options
  • Save stdray/065d5e57bd8d85d128a3 to your computer and use it in GitHub Desktop.
Save stdray/065d5e57bd8d85d128a3 to your computer and use it in GitHub Desktop.
class Point {
constructor(public x:number, public y:number) {}
}
class Color {
constructor (public r:number, public g:number, public b:number){}
}
class ColoredPoint extends Point {
constructor(x:number, y:number, public rgb:Color) {
super(x,y);
}
}
function moreRed(cp:ColoredPoint) {
cp.rgb.r++;
}
var p = new Point(0,0);
moreRed(p);
function cheat(f:(p:Point) => void) {
f(p);
}
cheat (moreRed);
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Point = (function () {
function Point(x, y) {
this.x = x;
this.y = y;
}
Object.defineProperty(Point.prototype, "__rtti__", {
get: function () {
return RT.ObjectType("Point");
},
});
Point.__rtti__ = RT.registerClass({
kind: "class",
name: "Point",
members: {
"x": { __typ__: RT.Num },
"y": { __typ__: RT.Num } },
extendsList: [],
constr: RT.ArrowType([RT.Num, RT.Num], RT.ObjectType("Point")),
statics: {
"prototype": { __typ__: RT.ObjectType("Point") } },
methods: {},
prototype: Point.prototype,
functionObject: Point,
implementsList: [] });
return Point;
})();
var Color = (function () {
function Color(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
Object.defineProperty(Color.prototype, "__rtti__", {
get: function () {
return RT.ObjectType("Color");
},
});
Color.__rtti__ = RT.registerClass({
kind: "class",
name: "Color",
members: {
"r": { __typ__: RT.Num },
"g": { __typ__: RT.Num },
"b": { __typ__: RT.Num } },
extendsList: [],
constr: RT.ArrowType([RT.Num, RT.Num, RT.Num], RT.ObjectType("Color")),
statics: {
"prototype": { __typ__: RT.ObjectType("Color") } },
methods: {},
prototype: Color.prototype,
functionObject: Color,
implementsList: [] });
return Color;
})();
var ColoredPoint = (function (_super) {
__extends(ColoredPoint, _super);
function ColoredPoint(x, y, rgb) {
_super.call(this, x, y);
this.rgb = rgb;
}
Object.defineProperty(ColoredPoint.prototype, "__rtti__", {
get: function () {
return RT.ObjectType("ColoredPoint");
},
});
ColoredPoint.__rtti__ = RT.registerClass({
kind: "class",
name: "ColoredPoint",
members: {
"rgb": { __typ__: RT.ObjectType("Color") } },
extendsList: ["Point"],
constr: RT.ArrowType([RT.Num, RT.Num, RT.ObjectType("Color")], RT.ObjectType("ColoredPoint")),
statics: {
"prototype": { __typ__: RT.ObjectType("ColoredPoint") } },
methods: {},
prototype: ColoredPoint.prototype,
functionObject: ColoredPoint,
implementsList: [] });
return ColoredPoint;
})(Point);
function moreRed(cp) {
cp.rgb.r++;
}
var p = new Point(0, 0);
moreRed(RT.__UNSAFE__(p));
function cheat(f) {
f(p);
}
cheat(RT.__UNSAFE__(moreRed));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment