zepto源码阅读(1)

(function (window){
    var zepoto = {};
    function Z(dom, selector){
        var i, len = dom ? dom.length : 0;
        for (i = 0; i < len; i++){
            this[i] = dom[i];
        }
        this.length = len;
        this.selector = selector || '';
    }
    zepto.Z = function(dom, selector){
        return new Z(dom, selector);
    }
    zepto.init = function(selector){
        var slice = Array.prototype.slice;
        var dom = slice.call(document.querySelectorAll(selector))
         return zepto.Z(dom, selector);
    }
    var $ = function(selector) {
        return zepto.init(selector);
    }
    window.$ = $;
    $.fn = {
        css: function (key, value){

        },
        html: function (value) {

        }
    }
    Z.prototype = $.fn; //为什么要写在$.fn下,再定义一个对象不行吗?这样做有什么优点?
})(window)

你可能感兴趣的:(zepto源码阅读(1))