Message from JavaScript discussions

July 2018

— Thanksss

— 

Getify is also an amazing teacher with great knowledge. Subscribe frontendMasters and u will learn a lot, best resource for frontend courses IMO

— Directly from cloud?

— Hi guys!

— Yea

— Welcome

— I need an help to understand a piece of code about prototype in JS. Someone who could help me?! : ]

— Share your code and ask your question

— Function RigidShape(center) {
this.mCenter = center;
this.mAngle = 0;
}

var Rectangle = function (center, width, height) {
RigidShape.call(this, center);
this.myType = 'Rectangle';
this.center = center;
this.width = width;
this.height = height;
}

var prototype = Object.create(RigidShape.prototype);
prototype.constructor = Rectangle;
Rectangle.prototype = prototype;`

Message permanent page

— I cannot understand the last 3 rows od the code. I'm following a tutorial but I cannot get the meaning to make an object (prototype), make its constructor the Rectangles constructor and then make the prototype of the Rectangle the object prototype created

Message permanent page

— Do you know how prototypes works?

— I thought to know, but maybe not. I try to explain how I think reading the code.

- var prototype = Object.create(RigidShape.prototype);
Here I create a new object which is an instance of RigidShape.

Message permanent page