How to edit a function after it’s created?
function foo(a, b) {
this.c = a+b;
}
var bar = new foo(2,3); //result: {'c':5}
//now I would like to create a new function, which is a bit different from the first
foo2 = foo;
foo2.d = a*b; //here I get an error: a is not defined
bar2 = new foo2(3,4);
No, I mean the result should be this:
function foo2(a, b) {
this.c = a+b;
this.d = a*b;
}
You can’t do exactly what you want, but there are other ways to do what you want.
A better way of doing this is like this…