views:

18

answers:

3

How can i call a YUI function that is wrapped inside a YUI().use from javascript?

example Below is a YUI function "runShowAnim" which executes animShow.run(); for an animation effect...

 var runShowAnim = function(e) {
     animShow.run();
 };

I want this effect to happen when i validate something in a javascript function. I tried to call it as below. But it doesn't seem to work.

function notifyUser(message) {
   document.getElementById("msgArea").innerHTML = message;
   runShowAnim();
}
A: 

If you want to call a function, you have to suffix the function name with () and include 0 or more comma separated arguments between them.

runShowAnim();

If the function doesn't have global scope (as yours will have if it is declared inside a function passed to use()) and not passed outside in some way then you can only do this from the same scope.

David Dorward
I think scope is a problem for me. How can i make a function inside YUI().use('anim', 'node', function(Y) { <function is present over here> }); have global scope?
Cliford Shelton
Don't use `var`
David Dorward
A: 

I think you're missing the parentheses.

function notifyUser(message) {
   document.getElementById("msgArea").innerHTML = message;
   runShowAnim(); // right here
}
Marko
I have the parentheses. Missed to put them in the question while I was putting just the required bits. The error I get is that the function runShowAnim is not defined
Cliford Shelton
Are they defined in the same scope?
Marko
A: 

YUI.thefunction()?

I think you need to call it with namespace too

something similar to

var X = function(){};
X.Y = function(){};
X.Y.Z = function(){};
X.Y.Z.foo = function(e){alert(e);}

//foo("me");<-error

X.Y.Z.foo("me");
jebberwocky