I am trying to make a matrix object. I have given it some properites. I
am trying to add a method. When I call the method by Test.showDims(...)
I want to only enter one input, that is the method by which to do it.
As you can see from the object definition that it corresponds to a
function that takes two inputs. When I try to run the script it does
nothing. So what is wrong and how do I fix it? Here is the script.
function showDims(input,method) {
// Depending on 'method' is 1 then shows an alert showing the
dimensions of
// 'input' and writes to the webpage if method is 2.
var Dims = dims(input); // Get dimensions
if (method == 1) {alert("Rows: " + Dims[0] + "\n" + "Columns: " +
Dims[1]);}
if (method == 2) {
document.write("Rows: " + Dims[0] + "<br>");
document.write("Columns: " + Dims[1] + "<br>");
}
}
function Matrix(matrixarray) {
this.M = matrixarray;
this.rows = this.M.length;
this.columns = this.M[0].length;
this.showDims(method) = showDims(this.M,method);
}
test = [
[1,2,3],
[4,5,6],
[7,8,9]];
Test = new Matrix(test);
document.write(Test.rows+"x"+Test.columns+"<br>");
Test.showDims(1);