1

How can I use same instance of one 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)

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.