js file for one script block only

Hi all,

Is it possible to reference a .js file that will only be used with one block of script.

The reason I ask is that we have a web page that uses a chart component but we need to update one of the charts to a later version and leave the other at the current version. The problem being they reference different .js files but with the same name and some of the same function names.

Any help is much appreciated.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
No, it doesn't work that way.  Javascript on a single page in your browser is all dumped into one big collection.  If you have more than one function with the same name, you will not be able to tell which one is being called.  

You may be able to have separate versions if you put the charts in 'iframes' in the page.  That should provide the isolation you need to keep them from conflicting with each other.  Items in an iframe run as a logically separate page.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
resourcesysAuthor Commented:
Thanks Dave, iframes isn't really an option at the moment so I'll have to think of something else.
>> If you have more than one function with the same name, you will not be able to tell which one is being called.  
As far as I know, the last definition of the function always overrides the previous definition(s), so you would/should always know :)

>>iframes isn't really an option
Well, then you will need to rename the conflicting function(s) OR create namespace(s) for them, but you will still need to alter any existing code base to prefix the function name with its namespace.

resourcesysAuthor Commented:
Thanks hielo, I'll check out namespaces.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.