如何使用$ .each在jquery中调用所有函数

时间:2013-10-09 00:24:04

标签: javascript jquery

我已经创建了许多函数,比如$ .redux.select,我想在dialog_finished事件触发时调用所有函数

这是field_select.js文件中的代码

(function($){
    "use strict";

    $.redux = $.redux || {};

    $(document).ready(function () {
        $.redux.select();
    });

    $.redux.select = function(){
        //some code here
    }   

})(jQuery);

这是redux.js文件中的代码

(function($){
    "use strict";

    $.redux = $.redux || {};

    $(document).ready(function () {

        var the_body = $(document);
        the_body.on('dialog_finished', function(event, window){
            //render all methods
            $.each($.redux, function( method, value ) {
                /*******************************************************************/
                   my problem is below , how to call $.redux.select() using $.each
                   or there is better way
                /*******************************************************************/
                $.redux.$method();
            });
        });

    });

})(jQuery);

1 个答案:

答案 0 :(得分:0)

$.each($.redux, function( name, value ) {
    value();  // call the function
});

http://jsfiddle.net/EAgfP/

$.each($.redux, function( name, value ) {
    $.redux[name]();  // call the function
});

http://jsfiddle.net/EAgfP/1/