开发者

global JS variables not available to functions defined in included JS files

开发者 https://www.devze.com 2023-03-27 21:45 出处:网络
I\'m trying to use a global JS variable that\'s dumped on the page by a view/template used to drive a JS solution. This has worked fine in a number of environments, but this week I\'ve found one envir

I'm trying to use a global JS variable that's dumped on the page by a view/template used to drive a JS solution. This has worked fine in a number of environments, but this week I've found one environment where my defined function (which 开发者_开发知识库is in an external JS included via a script tag) doesn't seem to access it.

When I step through the page line by line watching the variable in Chrome's dev tools, I can see the variable get declared in the global namespace, and it drops out of scope when the other function is called.

What is the explanation and how can I predict when this will/won't happen in the future? I've used other global variables through functions before... I haven't seen this though...

The function is ran on a $(document).ready() call.

0

精彩评论

暂无评论...
验证码 换一张
取 消