rgrove / jquery-yui3-rosetta-stone

A guide to idioms in YUI 3 and jQuery.
BSD 3-Clause "New" or "Revised" License
65 stars 20 forks source link

Erroneus example for jQuery's `$( ... ).each` #14

Closed yuchi closed 12 years ago

yuchi commented 13 years ago

From the actual example:

// jQuery

$('.foo').each(
  function() {
    this.some_method();
  }
);

// YUI

Y.all('.foo').each(
  function() {
    this.some_method();
  }
);

Should be:

$('.foo').each(
  function() {
    $(this).some_method(); // notice the wrapped `this`
  }
);

While this in the traverser in YUI is a Node object, in jQuery is the actual HTMLElement! Not only the example should be edited, but a little note IMO is required.

aristus commented 12 years ago

! Good catch.