ma*******@gmail.com wrote:
i have a html page with some javascript functions in a js file linked
to it.
now, if i create a function in the html page with the same name as one
of js functions, how can i call the function that exists on js file
(from html)?
You may copy the whole function:
// this one might be in you linked js file
function foo() {
alert("foo1");
}
// copy the function
var foo_old = foo;
// overwrite the existing function. Do it within another function
// as otherwise the parser might have overwritten foo before
// any execution
function tmp() {
window.foo = function() {
if (foo_old)
foo_old();
alert("foo2");
}
}
// call that function now
tmp();
// call the overwritten function
foo();
If you use objects with prototype, this might be easier:
function o() {
}
o.prototype.foo = function() {
alert("foo1");
};
o.prototype.foo_old = o.prototype.foo;
o.prototype.foo = function() {
if (this.foo_old)
this.foo_old();
alert("foo2");
};
new o().foo();
Daniel