<repo_name>sunnei/OOP-Jquery<file_sep>/pop-jquery.js
/**
 * Created by o on 2016/8/24.
 */
(function () {
    //str
    // 优化面向过程版
    function extend(obj, target) {
        for (var i in obj) {
            target[i] = obj[i];
        }
    };
    function $(selector) {
        if (selector) {
            var dom = document.querySelectorAll(selector);
            dom.mylength = dom.length;  //mylength 代替 length
            dom.__proto__ = $.prototype;
            return dom;
        }
    };
    $.fn=function(name,fn){
        $.prototype[name]= function () {
            this.each(fn,arguments)
            return this;
        }
    }
    $.extend = function (obj) {
        extend(obj, $.prototype)
    };
    $.extend({
        css: function (name, value) {
            this.each(function () {
                this.style[name] = value;
            })
            return this;
        },
        each: function (fn,argument) {
            if(fn)for(var t= 0,l=this.mylength;t<l;t++){
                fn.apply(this[t],argument);
            };
        }
    });
    window.$ = $;
}())
<file_sep>/README.md
# POP-Jquery
用面向过程(pop)实现 简单版 jquery 的架构设计，不是原生面向对象工厂模式版的jquery，pop版的优点是轻量，节省了内存，同时又能实现功能和效率，这里只是探讨架构，没有具体实现jq的全部功能，有兴趣可自行研究
<pre>   

// 面向过程版
//Created by o on 2016/8/24.

(function () {
    function extend(obj, target) {
        for (var i in obj) {
            target[i] = obj[i];
        }
    };
    function $(selector) {
        if (selector) {
            var dom = document.querySelectorAll(selector);
            dom.mylength = dom.length;  //mylength 代替 length
            dom.\_\_proto\_\_ = $.prototype;
            return dom;
        }
    };
    $.fn=function(name,fn){
        $.prototype[name]= function () {
            this.each(fn,arguments)
            return this;
        }
    }
    $.extend = function (obj) {
        extend(obj, $.prototype)
    };
    $.extend({
        css: function (name, value) {
            this.each(function () {
                this.style[name] = value;
            })
            return this;
        },
        each: function (fn,argument) {
            if(fn)for(var t= 0,l=this.mylength;t<l;t++){
                fn.apply(this[t],argument);
            };
        }
    });
    window.$ = $;
}())
