JavaScriptPatterns icon indicating copy to clipboard operation
JavaScriptPatterns copied to clipboard

Place of return statement in a jQuery plugin in code snippet | Chapter 8 Web Patterns

Open imrek opened this issue 8 years ago • 0 comments

On p. 178 your book provides an example of a jQuery plugin like this:

$.fn.yeller = function () {
    this.each(function (_, item) {
        $(item).val($(item).val().toUpperCase());
        return this;
    });
}

Shouldn't it actually return this only once after the loop (instead of every iteration) or, better yet, return this.each(), as in the documentation.

imrek avatar Jul 29 '16 14:07 imrek