zoukankan      html  css  js  c++  java
  • 再次理解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>
  • 相关阅读:
    [导入]微软轻量级“代码生成器”—Repository Factory使用(上)
    数据结构练习(41)数组中三个只出现一次的数字
    数据结构练习(43)字符串的组合
    数据结构练习(37)复杂链表的复制
    数据结构练习(36)二叉树两结点的最低共同父结点
    数据结构练习(34)对称子字符串的最大长度
    数据结构练习(38)树的子结构
    数据结构练习(39)二叉树前中后序遍历的非递归实现
    数据结构练习(42)八皇后问题
    数据结构练习(35)数组中出现次数超过一半的数字
  • 原文地址:https://www.cnblogs.com/heidsoft/p/3801254.html
Copyright © 2011-2022 走看看