你的位置:首页 > 软件开发 > Java > jQuery.pushStack()原型方法源码分析

jQuery.pushStack()原型方法源码分析

发布时间:2015-07-10 18:00:21
这次分析的方法跟前面不同,虽然pushStack也是原型方法之一,但是我们几乎从不用在页面调用,在参考手册里面也没有这个方法的使用说明,但是这个方法还是非常重要的,在使用很多jQuery的其他方式都会隐式的调用此方法:它为以下方法提供支持:‰ ‰ jQuery 对象遍历:.eq( ...

jQuery.pushStack()原型方法源码分析

这次分析的方法跟前面不同,虽然pushStack也是原型方法之一,但是我们几乎从不用在页面调用,在参考手册里面也没有这个方法的使用说明,但是这个方法还是非常重要的,在使用很多jQuery的其他方式都会隐式的调用此方法:

它为以下方法提供支持:

下面是1.7.1版本的源码

  // Take an array of elements and push it onto the stack  // (returning the new matched element set)  pushStack: function( elems, name, selector ) {    // Build a new jQuery matched element set    var ret = this.constructor();    if ( jQuery.isArray( elems ) ) {      push.apply( ret, elems );    } else {      jQuery.merge( ret, elems );    }    // Add the old object onto the stack (as a reference)    ret.prevObject = this;    ret.context = this.context;    if ( name === "find" ) {      ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;    } else if ( name ) {      ret.selector = this.selector + "." + name + "(" + selector + ")";    }    // Return the newly-formed element set    return ret;  },

原标题:jQuery.pushStack()原型方法源码分析

关键词:jquery

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录