I have a class called SizeHolder that stores a width, height, has a function to return an aspect ratio, as well as some accessor functions. However, it seems that creating new instances of that class overwrites the old one.
I've tried changing my compiler, but I really don't know what I'm doing wrong.
class SizeHolder {
constructor(w, h) {
self.w = w;
self.h = h;
}
aspectRatio() {
return (self.w / self.h);
}
getW() {
return self.w;
}
getH() {
return self.h;
}
}
var a = new SizeHolder(3111, 1777);
var b = new SizeHolder(5, 7);
console.log(a.getW()); //outputs 5
console.log(b.getW()); //outputs 5
I would expect a.getW() to return 3111, but it instead outputs 5?