Click to See Complete Forum and Search --> : Is this possible? Getting around bad code...


rodzilla
03-07-2003, 11:30 AM
I wrote a script that uses window.prompt to get user input. It is stored in an external .js file. It is on a page with several other external .js files, one of which (not written by yours truly of course) literally defines a function called "prompt," which stupidly writes the argument string to the status bar and basically cancels out the core JavaScript function of "prompt."

Is there a way to get around this problem, some way to tell JavaScript to use its core functionality instead of the user-defined "prompt," or am I stuck having to go through the trouble of getting someone else to modify their script?

khaki
03-07-2003, 11:47 AM
Hi rodzilla...

Couldn't you just copy the code from the external JS file that is giving you fits, modify it to fit your own needs, save it as your own file, and reference your file instead of the original?

It seems a lot simpler than developing a work-around for the prompt issue in someone else's page.
(or have I oversimplified the problem?)

k

rodzilla
03-07-2003, 11:51 AM
Of course I *could* do that, but because it was written by this 3rd party consulting company, changing *anything* they've done is--well, a pain in the arse, politically speaking, especially when there is a non-technical manager in between me and the 3rd party.

On the other hand, I'm sure I could probably change the code in the other .js and nobody would notice. ;)

boojum
03-07-2003, 12:01 PM
if i were you i would have my manager have some words with the 3rd party. they probably would be happy to either change the original or offer a 'version' that dispenses your problem. everything's legal, everyone's happy.

rodzilla
03-07-2003, 12:18 PM
I really did hope to get some kind of magical answer. I can't believe how idiotic someone would be to name a function the same thing as a core function. Ugh, such is my corporate life.

pyro
03-07-2003, 12:32 PM
Originally posted by rodzilla
I can't believe how idiotic someone would be to name a function the same thing as a core function.Yes, and if you point it out to them that they did this, I would think they would be more than happy to change it.

Dan Drillich
03-07-2003, 12:49 PM
This JS “feature” which you are experiencing is described nicely in this page –
http://www.woodger.ca/js_disc.htm


Data Type: A variable's data type is defined by the last value assigned to it (so called "dynamic typing"). A variable could be a number on one line, then assigned a string value and later be assigned an object reference. JavaScript would just change its data type on-the-fly with each assignment.


Since a function in JS is data, the above applies to functions as well.

Vladdy
03-07-2003, 01:37 PM
hmm... You could try to add this line prior to their code:
realPrompt = window.prompt
and then use
realPrompt('prompt string');
in your code... but that is one f#$%ed-up way do deal with the problem....

Dan Drillich
03-07-2003, 02:21 PM
Vladdy,

It won’t do the trick. realPrompt will also point to the user defined prompt().

Vladdy
03-07-2003, 02:39 PM
I think you are right....