I superficially understand how functions are overridden in javascript ... the last method loaded (with the same name -- no signatures) is executed.
My web page add on is distributed as a js script. As part of it's functionality, a third party script calls a method 'x()' when it's loaded. Consumers of my add on may already have an x() method on their web page to interact (in their own way) with that third party script. If they don't though, I want to execute mine. Problem being that my x() overrides theirs, which is not the behaviour wanted.
Personally I think it's a bit crazy, with web latency, to override functions with 'last one rules' . Guess, that's another story.
Fortunately, I can look for a specific div and know that the client will have their own x() method and have conditionally added my method as a separate script. That way my method is only present on the page if theirs is not.
Is there a more elegant way of doing this? Effectively I'd like an x() that underrides the client's x(). I'm concerned that as some point I will not be able to easily check for their x(). Btw ... checking for the presence of x() using typeof === 'function'
just returns true for my x().