Skip to content

Instantly share code, notes, and snippets.

@pmcao
Last active May 9, 2016 22:44
Show Gist options
  • Save pmcao/c13212db0a40e6ff4509539fa37bf8d5 to your computer and use it in GitHub Desktop.
Save pmcao/c13212db0a40e6ff4509539fa37bf8d5 to your computer and use it in GitHub Desktop.
// classA.ts
export class A {
a:string;
}
// app.ts
class C extends B {
c:string;
whoAmI() {
let t = Object.getPrototypeOf(this);
let base: string = "";
console.log("Traversing class hierarchy...");
while (t.constructor.name !== "Object"){
console.log(t.constructor.name);
base = t.constructor.name;
t = Object.getPrototypeOf(t);
}
console.log("Base is class " + base);
}
foo (x:XX,y:YY) {
for (var arg in arguments){
console.log(arguments[arg]);
}
}
}
var c = new C();
c.whoAmI();
var x = new XX();
var y = new YY();
c.foo(x, y);
// Output:
Traversing class hierarchy...
C
B
A
Base is class A
XX {}
YY {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment