this
in MyFunction1
referes to the global object in that case(for browsers it is window
) , because you call MyFunction1
as function and you don't create an object by using new MyFunction1()
.
Another thing to be noted. You should not use eval
when it is possible to do it without eval.
You can do the same thing using:
function MyMethod(name, fn) {
MyFunction1.prototype[name] = fn;
}
Using eval
prevents you from using optimization tools or tools to validate your code. At least most of these tools don't take eval
into account or even give a warning about that you are using it.