You can use the ECMAScript 5.1 standard:
Object.getPrototypeOf(cursor)
For really quite old versions of browsers, you could attempt to fall back to __proto__
if Object.getPrototypeOf
doesn't exist, but you can decide if those browsers are important given your specific context.
Here is an example that shows this. bar.prototype
doesn't work, because it is an instance. getPrototypeOf
works and gives you the same answer as the discouraged __proto__
.
class Foo {
constructor(name: string) {
}
}
class Bar extends Foo {
}
var bar = new Bar('x');
console.log(bar.prototype);
console.log(Object.getPrototypeOf(bar));
console.log(bar.__proto__);
So you could write the "pleases everyone"...
if (Object.getPrototypeOf) {
console.log(Object.getPrototypeOf(bar));
} else if (bar.__proto__) {
console.log(bar.__proto__);
}
Final curve-ball... __proto__
is likely to become standardised in ECMAScript 6... worth bearing in mind!