Having trouble locating documentation for this issue. I devised a JavaScript class in the following manner:
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
area = function() {
return this.height * this.width;
}
}
However, it failed to function properly on JSFiddle and I was advised to use this format:
var Polygon = function(height, width) {
this.height = height;
this.width = width;
this.area = function() { return this.height * this.width; }
}
I'm aware that there are multiple ways to achieve the same result. I am curious if this approach is similar to C++ where you can create a pointer like... Polygon *myPoly = new Polygon(3, 4); rather than Polygon myPoly(3, 4); or if it's purely stylistic. Additionally, any reasons as to why one method works on JSFiddle while the other does not would be appreciated.