0

I am using a plugin JS and need to call a function in it.

It is having functions inside a variable like,

var win = window;
var Page = function(pageOptions, callback) {
 function abc(){
 --------
 }
 function xyz(){
 ------
 }
};
win.Sales = {
 Page: Page
};

Now, I need to call a function abc(). How can I call it. Already tried with win.Sales.page.abc();.

Please help me out on this. Thanks in advance.

asked Sep 16, 2011 at 9:39
2
  • just say win.Sales.Page it will call the function. since Page contains the reference to a function. Commented Sep 16, 2011 at 9:41
  • @Sharma: I need to call abc() in it. Anyway I did what u suggested. Didn't work. Commented Sep 16, 2011 at 9:46

2 Answers 2

2

You cannot do that with your configuration because the functions are local or private.

You should make them accessible globally like:

var Page = function(...) {
 ...
};
Page.abc = function() {
 ...
};

That way, abc is a property of Page, and you can then access it like Page.abc and execute it like Page.abc(). Functions are basically also objects so they can have properties too.

answered Sep 16, 2011 at 9:43
Sign up to request clarification or add additional context in comments.

2 Comments

Its a plugin for drawing some charts. I cannot change it and also I see that Page is getting declared in win.Sales.
@Max: Then you're out of luck I think, because the idea of those private variables/functions is that you cannot access them outside.
1

You cant call function abc since it is declared as a private member of the function referenced by variable Page.

If you want to call the function You have to make it as a property of the variable Page.

var Page = function(){
 .........
 .........
 .........
}
Page.abc = function(){
}

But there is another problem of variable scoping like if there is another variable x defined in function Page and used inside function abc, it will not work.

Anyway since you've said it is a js plugin I do not think it will be possible for you to change the function Page. So the answer will be No you cannot do that.

answered Sep 16, 2011 at 9:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.