【问题标题】:zepto function not what's selector.itemzepto 函数不是什么是 selector.item
【发布时间】:2017-03-22 20:16:31
【问题描述】:

当我阅读zepto的源代码时,我发现有一个我无法理解的东西。

例如: 'not' 函数:什么是 selector.item? 有人说 IsFunction(selector.item) 是为数组排除选择器。 但是如何排除呢?为什么要排除?

这是源代码:

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)
    })
}

【问题讨论】:

    标签: javascript zepto


    【解决方案1】:

    我最近也看了zepto的源码,在MDN上找到了答案,就是排除HTMLCollection。因为 HTMLCollection 类似于数组,并且具有 item 方法。这是文档HTMLCollection.item

    【讨论】:

    • 包含一个指向答案的链接不是一个好的链接。请阅读此how-to-answer