使用.each在.resize上执行函数数组 [英] using .each to execute array of functions on .resize

查看:65
本文介绍了使用.each在.resize上执行函数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在名为Response的对象中,该对象可同时触发.ready.resize上的功能...

In the an object called Response this works to trigger a function on .ready and .resize simultaneously...

Response.action = function ( func ) {
    if ( typeof func !== 'function' ) { return false; } // If func is not a function, return false.
        $(function () { func(); $(window).resize( func ); }); // 
    return func;
}; // Response.action

...使用它来称呼它:

...using this to call it:

Response.action( myfunc );
function myfunc() { 
    //do stuff
}

(我们在此线程中进行了研究.)

(We worked that out in this thread.)

我想制作另一个版本,该版本可以对功能的数组做同样的事情,用法如下:

I'd like to make another version that can do the same thing for an array of functions, with usage like this:

Response.actionSet( [myfunc1, myfunc2] );
function myfunc1() { 
    //do stuff
}
function myfunc2() { 
    //do stuff
}

我如下尝试了它,并且尝试了其他所有我想不到的咒语,但是我没有使它起作用.也没有错误消息.谁能推荐如何使它正常工作:

I tried it as below and every other incantation I could imagine, but I haven't got it to work. No error messages either. Can anyone recommend how to get this working:

Response.actionSet = function ( arr ) {
        if ( arr.isArray !== true ) { return false; } // If arr is not an array, return false.
        $.each(arr, Response.action(this)); // iterate over arr array
        return arr;
}; // Response.actionSet

推荐答案

您有一个小错误;应该是$.each(arr, function() { Response.action(this); });

You have a small error; it should be $.each(arr, function() { Response.action(this); });

Response.actionSet = function(arr) {
    if(!$.isArray(arr)) return false;
    $.each(arr, function() { Response.action(this); });
    return arr;
};

这篇关于使用.each在.resize上执行函数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆