Message from JavaScript discussions

July 2018

— Share your code and ask your question


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

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

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

— 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

— - prototype.constructor = Rectangle;
Here I make Rectangle the constructor of the object I created, am I right?

Message permanent page

— Hi, im new into JS!

— Anyone know cors?

— Drop a link on this (stupid imo) tutorial

— I bet it's a new operator sect

— Https://

— I dont like his composition code with Object.assign, but fully agree with the concept