.constructor JavaScript. .
, -, , , - :
const myCar = new Racecar();
console.log(myCar.constructor);
const car2 = new myCar.constructor();
console.log(car2.constructor);
, .constructor . , .constructor , JavaScript, , .
, .constructor , - - . , , - - JavaScript. , ( ), JavaScript, .
, - , - -. , .
instanceof .constructor. , .prototype ( ) .
.constructor ( ). , . , ES5:
function Car () {}
console.log(Car.prototype.constructor);
function Racecar () {}
Racecar.prototype = Object.create(Car.prototype);
Racecar.prototype.constructor = Racecar;
var myCar = new Racecar();
console.log(myCar.constructor);
ES6 :
class Car {}
class Racecar extends Car {}
const myCar = new Racecar();
console.log(myCar.constructor);
, - ES6, .constructor. ? factory , , , . . "Factory vs vs " .