Given this code:
/**
* Transform base class
*/
function Transform() {
this.type = "2d";
}
Transform.prototype.toString = function() {
return "Transform";
}
/**
* Translation class.
*/
function Translation(x, y) {
// Parent constructor
Transform.call(this);
// Public properties
this.x = x;
this.y = y;
}
// Inheritance
Translation.prototype = Object.create(Transform.prototype);
translation = new Translation(10, 15);
console.log(translation instanceof Transform); // true
console.log(translation instanceof Translation); // true
console.log(translation.__proto__); // Transform
console.log(translation.constructor); // Transform
Why translation.constructor
is Transform
and not Translation
?
Also, which property allows instanceof
to know that translation
is an instance of
Translation
(if it's not __proto__
nor constructor
)?