开发者

Java Script: Using Same Instance in two diffrent .js

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜