A
A
ApmeM2011-07-29 15:31:35
JavaScript
ApmeM, 2011-07-29 15:31:35

Loading JavaScript into local context?

I have a JavaScript file with content like

var param1=function<br/>
var param2=100500<br/>

That is, all variables become global.
Now the file is connected with the script tag.

The question is whether it is possible to load this file so that all these variables are in the context of the current function. Like this:
(function(){<br/>
 // load script file<br/>
}())<br/>

and the variables will no longer be global.

ZYZH the original file is not mine, and I cannot make any changes to it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2011-07-29
@taliban

You can't, wrap your content in a function and then call it in the right context so that it returns the right data.

G
gaelpa, 2011-07-29
@gaelpa

eval, even though he is angry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question