• 再次理解JavaScript原型链和匿名函数


    <!---------------------------------------------
    1、演示匿名加载
    2、js单进程执行流
    3、原型链理解
       a、__proto__:属性每个对象都有
       b、prototype:类型本身
    heidsoftg@gmail.com
    ---------------------------------------------->
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script type="text/javascript">
            // (function(){
            //     console.info(this);
            //     console.info(arguments);
            // }(window));
    
            // (function(){
            //     console.info(this);
            //     console.info(arguments);
            // })(window);
            // 
            console.log(window);
            console.log("Step=========================================1");
            (window);//传入参数
            (function(a,b){
                console.log("a="+a);
                console.log("b="+b);
            });
            console.log("Step=========================================2");
            (function(aObject,bObject){
                console.log("aObject="+aObject);
                console.log("bObject="+bObject);
            })(window);
    
            console.log("Step=========================================3");
            (function(aWin,bUndefined){
                console.log("aWin="+aWin);
                console.log("bUndefined="+bUndefined);
            })(window,undefined);
            console.log("Step=========================================4");
            (function(aWin,undefined){
                undefined="fuck undefined....";
                console.log("aWin="+aWin);
                console.log("undefined="+undefined);
            })(window);
    
    
            console.log("Step=========================================5");
            var testObject1={a:1,b:2};
            console.log("Step=========================================6");
            console.log(testObject1.__proto__);
            console.log("Step=========================================7");
            console.log(testObject1.__proto__);
            testObject1.__proto__ = new Object({a:2,b:5});
            console.log("Step=========================================8");
            console.log(testObject1.prototype);
            console.log("Step=========================================9");
            console.log(testObject1);
            testObject1.prototype= new Object({a:2,b:5});
            console.log("Step=========================================10");
            console.log(testObject1);
    
            var Person = function(){};
    
            Person.prototype.Say= function(){
                alert("Person say");
            };
    
            Person.prototype.Salary=50000;
            var Programmer = function(){};
            Programmer.prototype=new Person();//var p1.__proto__=Person.prototype
            Programmer.prototype.WriteCode = function(){
                alert("programmer write code");
            };
    
            Programmer.prototype.Salary=500;
            var p = new Programmer();
            //p.__proto__=Programmer.prototype;
            //Programmer.prototype.__proto__=Person.prototype;
            //p.__proto__.__proto__=Person.prototype
    
            p.Say();
            p.WriteCode();
            alert(p.Salary);
    
    
        </script>
    </head>
    <body>
        
    </body>
    
    </html>
  • 相关阅读:
    使用迭代器模式批量获得数据(C#实现)
    如何从技术上预防抢票软件刷屏
    如何用Tesseract做日文OCR(c#实现)
    我的.net开发百宝箱
    程序员必备基础:Git 命令全方位学习
    Java 异常处理的十个建议
    50道Java集合经典面试题(收藏版)
    记一次接口性能优化实践总结:优化接口性能的八个建议
    100道MySQL数据库经典面试题解析(收藏版)
    800+Java后端经典面试题,希望你找到自己理想的Offer呀~
  • 原文地址:https://www.cnblogs.com/heidsoft/p/3801254.html
Copyright © 2020-2023  润新知