Jquery.each()和Array.prototype.forEach()方法的区别 [英] Difference in Jquery.each() and Array.prototype.forEach() method

查看:98
本文介绍了Jquery.each()和Array.prototype.forEach()方法的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jquery.each()和Array.prototype.forEach()方法之间是否有任何区别,因为array.forEach()方法也可用于循环具有length属性的类数组对象。我看到的唯一区别是放置参数,还有什么区别呢?

Is there any difference between Jquery.each() and Array.prototype.forEach() method since array.forEach() method can also be used to loop over array-like objects with length property.The only difference i see is placement of arguments ,what else can be the difference in them?

 I found this:
 var obj = { one:1, two:2, three:3, four:4, five:5 };

jQuery.each(obj, function(i, val) {
  $("#" + i).append(document.createTextNode(" - " + val));
});

我想知道的是,jquery.each()是否为没有length属性的对象调用函数? ?

What i wan to know is ,do jquery.each() invokes function for object without length property??

推荐答案


  • 在回调中放置参数。

    • Placement of arguments in the callback.

      回调中的参数数量( .forEach()可让您获得对原始集合的引用。)

      Quantity of arguments in the callback (The .forEach() gives you get a reference to the original collection.)

      回调中的默认值。 (在jQuery中它是当前项,在 .forEach()它是JavaScript的默认值)

      Default this value in the callback. (In jQuery it's the current item, in .forEach() it's the JavaScript default)

      能力在回调中手动设置值。 (jQuery不提供此选项, .forEach()允许您通过第三个参数。)

      Ability to manually set the this value in the callback. (jQuery doesn't give this option, .forEach() lets you via a third argument.)

      避免稀疏数组上的非定义属性。 ( .forEach()避免它们,jQuery包含它们。)

      Avoidance of non-defined properties on sparse Arrays. (The .forEach() avoids them, jQuery includes them.)

      他们的行为方式非常不同。 jQuery不会尝试遵守或补充标准行为。

      They're very differently behaving methods. jQuery's doesn't make any attempt to be compliant with or complimentary of the standard behaviors.

      这篇关于Jquery.each()和Array.prototype.forEach()方法的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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