亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Prototype chain in jquery
歐陽(yáng)克
歐陽(yáng)克 2017-07-05 10:36:08
0
4
837
var jQuery = function(global, factory) {
    return new jQuery.fn.init();
}

jQuery.fn = jQuery.prototype = {
    constructor: jQuery,
    init: function() {
        this.jquery = 3;
        return this;
    },
    each: function() {
        console.log('each');
        return this;
    }
}

jQuery.fn.init.prototype = jQuery.fn;

// init構(gòu)造函數(shù)
jQuery().each().each()

The above is a piece of jQuery source code. My question is why the second each function in the last line of the code can still be executed

歐陽(yáng)克
歐陽(yáng)克

溫故而知新,可以為師矣。 博客:www.ouyangke.com

reply all(4)
洪濤

This in the prototype points to the instance object, return this in each to return this object, thereby realizing chain calls

滿天的星座

Two eachs have the same effect as one each, and the objects are all jQuery

Peter_Zhu

Because what you are returning is this, let alone two, 10 will do too

世界只因有你

Chain programming

return this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template