M
mitch
Is there a way to reassign a function? I tried this:
function func() { alert("func"); }
function func2() { alert("func2"); }
function testFunc() {
document.func = func2;
func();
}
and it prints "func" not "func2". I'd like to be able to override the
global function "func" to make it do something else. Is there a
trick to do it? Thanks.
The reason I want to do it is for unit testing. I have some test
code I'm writing, and I want to call the production code and override
some of the functions in the production code, making other
functions unit-testable. I would prefer to do it without changing
the production code.
function func() { alert("func"); }
function func2() { alert("func2"); }
function testFunc() {
document.func = func2;
func();
}
and it prints "func" not "func2". I'd like to be able to override the
global function "func" to make it do something else. Is there a
trick to do it? Thanks.
The reason I want to do it is for unit testing. I have some test
code I'm writing, and I want to call the production code and override
some of the functions in the production code, making other
functions unit-testable. I would prefer to do it without changing
the production code.