I want to create a javascript class of my own. My question is, how do i create a function with two differents effects depending on the context.
Here is an example :
function Matrix(str) {
this.G = 2 dim array;
this.e = function(x,y){
G[x][y] = 3 // if the user types myGraph.e(1,1) = 3;
return G[x][y] // if user call myGraph.e(1,1);
}
So how can I have two different results with only one function ? myGraph.e(1,1) = 3 and myGraph.e(1,1)
Thx !
Slightly modifying @Esalija’s answer:
NB: it’s more common for the first dimension of a 2-D array to represent
y, notx.