> Is this the suggested syntax for a java script "class"?

Is this the suggested syntax for a java script "class"?

Posted at: 2014-12-18 
It's a constructor of objects not a class. Javascript doesn't have classes, just objects and prototypes(but perhaps that's why you said "class"). But yes, a constructor looks like that you make a function with certain parameters and then you add this.property or this.method and define those properties/methods. Then you instantiate objects with new Rect.

function Rect(x, y, width, height, color, number) {

this.x = x;

this.y = y;

this.width = width;

this.height = height;

this.color = color;

this.number = number;



this.draw = function() {

var canvas = document.getElementById("canvas");

var context = canvas.getContext("2d");



context.beginPath();

context.rect(this.x, this.y, this.width, this.height);

context.fillStyle = this.color;

context.fill();

context.stroke();

}