It’s just to properly reset the constructor
property to accurately reflect the function used to construct the object.
Sub.prototype = new Super();
console.log(new Sub().constructor == Sub);
// -> 'false'
Sub.prototype.constructor = Sub;
console.log(new Sub().constructor == Sub);
// -> 'true'
More Related Contents:
- Can I construct a JavaScript object without using the new keyword?
- Prototypical inheritance – writing up [duplicate]
- What are the nuances of scope prototypal / prototypical inheritance in AngularJS?
- What is the reason to use the ‘new’ keyword at Derived.prototype = new Base
- Use of .apply() with ‘new’ operator. Is this possible?
- JavaScript inheritance and the constructor property
- What is the significance of the Javascript constructor property?
- Understanding prototypal inheritance in JavaScript
- What is the `constructor` property really used for? [duplicate]
- Setting methods through prototype object or in constructor, difference? [duplicate]
- Grasping prototypical Inheritance through pseudoclassical instantiation (JavaScript)
- Objects don’t inherit prototyped functions
- Assigning prototype methods *inside* the constructor function – why not?
- JavaScript: What dangers are in extending Array.prototype?
- Parse JSON String into a Particular Object Prototype in JavaScript
- Asynchronous operations in constructor
- Javascript when to use prototypes
- Create a reset of javascript Array prototype when Array.prototype has been modified?
- Javascript Class Inheritance For Functions
- When is it appropriate to use a constructor in REACT?
- Understanding Crockford’s Object.create shim
- Define Private field Members and Inheritance in JAVASCRIPT module pattern
- ‘this’ keyword, not clear
- How to check if a Javascript Class inherits another (without creating an obj)?
- Typescript: can not access member value in inherited class constructor
- Javascript: hiding prototype methods in for loop?
- OO Javascript constructor pattern: neo-classical vs prototypal
- JavaScript Event prototype in IE8
- prototypal inheritance concept in javascript as a prototype based language
- ES6 – declare a prototype method on a class with an import statement