Code:
Array.prototype.twod = function() {
var self = this;
return {
rotate: function() { blablbla "self" refers to the array },
mirror: function() { blabla }
};
};
Then [bla,bla,bla].twod().rotate() would do what you want. Not quite what you had in mind though.
Something more general might be:
Code:
function Matrix(arr) {
this.array = arr;
}
Matrix.prototype.get = function(i,j) {
return this.array[i][j];
};
Matrix.prototype.set = function(i,j, value) {
return this.array[i][j] = value;
};
Matrix.prototype.rotate = function(angle) {
// blablabla
};
// and so on
Then just use your Matrix object instead.