Edit: Also check JavaScript YUI3 using global variables?
Considering javascript's asynchronous nature, tabview
is not necessarily rendered before alert()
is called on it outside the YUI block. Seeing "undefined" in the alert box in this case means that the variable has been declared but not assigned to any value. If the variable wasn't accessible, alert()
would fail due to an uncaught "ReferenceError".
So, in trying to guessing your intention, if you want to examine the tabview object, you might want to use console.log()
instead of alert()
to see the output in your browsers console, and put it within the YUI block right after render()
:
var tabview;
YUI().use('tabview', function(Y) {
tabview = new Y.TabView({srcNode:'#demo'});
console.log(tabview); //defined
tabview.render();
console.log(tabview);
});
In order to use tabview
outside the YUI block, ensure that it is ready. As a quick example:
Y.on("domready", function() {
console.log(tabview);
}