Javascript >> Reset an Inherited Constructor Property

When an object inherits its prototype from another object, it also inherits the supertype's constructor property.

For example:


function Blogger() { }
Blogger.prototype = Object.create(BloggerClass.prototype);
let myBlog= new Blogger();
myBlog.constructor // function BloggerClass(){...}



You can manually set Blogger's constructor property to the Blogger object.


Blogger.prototype.constructor = Blogger;

myBlog.constructor // function Blogger(){...}

Comments

Popular posts from this blog

Tech Duos For Web Development

CIFAR-10 Dataset Classification Using Convolutional Neural Networks (CNNs) With PyTorch

Long-short-term-memory (LSTM) Word Prediction With PyTorch