zoukankan      html  css  js  c++  java
  • 01-jQuery的基本结构

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>01-jQuery的基本结构</title>
    
        <script>
            /* 
            1.jQuery的本质是一个闭包
            2.jQuery为什么要使用闭包来实现
                为了避免多个框架的冲突
            3.jQuery如何让外界访问内部定义的局部变量
                window.xxx = xxx;
            4.jQuery 为什么要给自己传递一个window参数?
                为了方便后期压缩代码
                为了提升查找的效率
            5. jQuery 为什么要给自己传递一个undefined参数?
                为了方便后期压缩代码
                IE9一下的浏览器undefined可以被修改,为了保证呢不适用的undefined不被修改,所以需要接受一个正确的undefined
        */
            (function (window, undefined) {
                jQuery = function(){
                    return new jQuery.prototype.init();
                }
    
                jQuery.prototype = {
                    constructor:jQuery
                }
    
                jQuery.prototype.init.prototype = jQuery.prototype;
                window.jQuery = window.$ = jQuery;
            })(window);
    
    
            (function f1() {
                var num = 10;
                window.num = num;
            })();
    
            (function f2() {
                var num = 20;
            })();
    
            console.log(num);
    
    
            var value = 20
            function f3(){
                var value = 10;
                console.log(value);
            }
        </script>
    </head>
    
    <body>
    
    </body>
    
    </html>

    jQuery基本架构:

    (function(window, undefined){
        var njQuery = function(){
            return new njQuery.prototype.init();
        }
    
        njQuery.prototype = {
            constructor: njQuery
        }
    
        njQuery.prototype.init.prototype = njQuery.prototype;
        window.njQuery = window.$ = njQuery;
    })(window);
    不考虑业务场景,一味的争执技术的高下,都是耍流氓。
  • 相关阅读:

    今天的收获080716
    手机写博客
    修改加速软件之本地分流(突破电信上网限制)
    Linux并不是传说中的那么不变
    Ubuntu Linux下的几款“磁盘操作阐明器”对比
    在SuSE中设置开机主动启动挨次
    Fedora显卡驱动的装配
    新Qt主题引擎让GNOME下KDE程序更舒服
    Ubuntu的运用总结
  • 原文地址:https://www.cnblogs.com/leoych/p/14853267.html
Copyright © 2011-2022 走看看