开发者

Java Script: Using Same Instance in two diffrent .js

开发者 https://www.devze.com 2023-03-20 21:30 出处:网络
How can I use same instance of on开发者_StackOverflow社区e particula .js across all .js functions

How can I use same instance of on开发者_StackOverflow社区e particula .js across all .js functions

For eg: var test = new Test();

this test i need to use when ever I want to access Test() function(i.e same instance)


It depends a little on what exactly your code looks like, but:

window['test'] = new Test();

should generally do the trick. After that, any scripts in your page should be able to see "test" as a global variable, which is the same as being a property of the window object.


Or you could simply omit the var part and make it a globally accessible instance of Test() like this.

test = new Test();

EDIT: Sorry I didn't see that you need it across functions.

0

精彩评论

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