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.

Thanks.

resourcesys
resourcesysAsked:
Who is Participating?
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.
0

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.
0
hieloCommented:
>> 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.

FYR:
http://www.kenneth-truyers.net/2013/04/27/javascript-namespaces-and-modules/
0
resourcesysAuthor Commented:
Thanks hielo, I'll check out namespaces.
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.