Migration from YUI2 to YUI3 and early

I want to port javascript to my site from YU2 to YUI3, but I'm just a poor amateur programmer and I'm stuck in the first trap.

I have the following code:

MyApp.Core = function() {  
    return {  
        init: function(e, MyAppConfig) {  
            if (MyAppConfig.tabpanels) {  
                MyApp.Core.prepareTabpanels(MyAppConfig.tabpanels);  
            }  
        },  
        prepareTabpanels: function(tabpanels) {  
            // Code here
        }  
    }  
}();  

var MyAppConfig = {  
    "tabpanels":{"ids":["navigation"]}  
};

YAHOO.util.Event.addListener(window, "load", MyApp.Core.init, MyAppConfig);

How to pass an object MyAppConfigto a function MyApp.Core.initusing the YUI3 "domready" event listener?

Thanks in advance!

+1
source share
1 answer

You should be able to do something like:

var MyApp = {};
    MyApp.Core = function(){ return {  
    init: function(MyAppConfig) {  
        console.log(MyAppConfig);
    },  
        prepareTabpanels: function(tabpanels) {  
    // Code here
    }  
}  
}();

var MyAppConfig = {  
    "tabpanels":{"ids":["navigation"]}  
};

YUI().use('node', 'event', function(Y){
    Y.on('domready', MyApp.Core.init, this, MyAppConfig);
});

Please note that the event is not passed as the first parameter, this is a config.

Y.on takes parameters such as <event_type>, <callback_function>, <context>, <params>..

any parameter after the third element is passed to the callback function, so MyAppConfig becomes the first parameter in your init.

. API YUI3: http://developer.yahoo.com/yui/3/api/YUI.html#method_on

+1

Source: https://habr.com/ru/post/1795330/


All Articles