zepto function not what's selector.item

93 Views Asked by At

When I read source code of zepto, I found there is a something that I can't understand.

For example: 'not' function: what's selector.item? There is someone said IsFunction (selector.item) is to exclude the selector for the array. But how to exclude? And why exclude?

This is source code:

else {
    var excludes = typeof selector == 'string' ? this.filter(selector) :
        (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)

    this.forEach(function(el){
        if (excludes.indexOf(el) < 0) nodes.push(el)
    })
}
1

There are 1 best solutions below

1
对角另一面 On

I also read the zepto source code recently, I had found the answer from MDN, It's to exclude HTMLCollection. Because HTMLCollection is array like, and has the method item. Here is document HTMLCollection.item