I've defined a javascript class for matrix transformations (of points to be drawn on an html5 canvas) which has multiple methods (e.g. multiply,rotate, scale, translate). In my rotate method, I need to call multiply, but since it is another method defined within the class, it has to be called in a way different from if was called outside of the class definition. For the class constructor, I have:
function Transform() {
this.identity();
}
and for the rotate method:
Transform.prototype.rotateX = function(rad) {
var c = Math.cos(rad);
var s = Math.sin(rad);
var rx = [[1, 0, 0, 0],
[0, c, -s, 0],
[0, s, c, 0],
[0, 0, 0, 1]];
this.m = multiply(rx, this.m);
document.write('matrix rx:<br />');
display(rx);
document.write('rx * this.m =<br />');
display(this.m);
};
I'm coming from a C++ background with OOP, so this way of defining classes seems a little strange, but it seems that you should be able to call a function defined in the class without using the dot operator similar to how in C++ if you have a method defined using the scope qualification operator, you can freely access any of the class' data. For some reason, in javascript, this must not be the case, as I'm getting the error:
Uncaught ReferenceError: multiply is not defined
What is the proper way to call methods defined in a Javascript class both inside and outside of the class definition?
multiplydefined.... you might have to usethis.multiplyif it is added to the prototype