zoukankan      html  css  js  c++  java
  • js 小练习题

    <script>
            /*1.结论,IIFE中运行顺序3,1,执行test(4),会传递参数*/
        
            /*var a=5;
            var test = (function(a){
                console.log(1);
                console.log("a:",a);
                this.a = a;
                return function(b){
                console.log(2);
                console.log("b:",b);
                    return this.a+b;
                }
            }(function(a,b){
                console.log(3);
                console.log("a:",a,"b:",b);
                return a;
            }(1,2)));
        console.log(test(4));
        var test1 = (function(c){
            console.log("c:",c);
            return function(d){
                
                console.log("d:",d,"arguments:",arguments); 
                return d;
            };
        }(1));
        console.log(test1(5,7,8)) //d: 5 arguments: [5, 7, 8]
        */
        /*2 这里需要注意 函数变量的提升覆盖 第一个会被覆盖*/
        
        /*var x = 1,y = z = 0;
        function add(n){
            return n=n+3;
        }
        y = add(x);
        function add(n){
            return n=n+1;
        }
        z = add(x);
        console.log(x);    
        console.log(y);    
        console.log(z);    */
        
        /*3 */
        
        function People(){
            this.name = 'Tim';
            this.sayHello = function(){
                console.log('People:'+this.name);
            }
        }
        
        function Man(name){
            this.name = name;
            this.sayHello = function(){
                console.log('Man:'+this.name);
            }
        }
        
        Man.prototype = new People();
        var man = new Man('Jim');
        man.sayHello();
        People.call(man);
        man.sayHello();
        
        </script>

    <script>
            /*1.结论,IIFE中运行顺序3,1,执行test(4),会传递参数*/
        
            /*var a=5;
            var test = (function(a){
                console.log(1);
                console.log("a:",a);
                this.a = a;
                return function(b){
                console.log(2);
                console.log("b:",b);
                    return this.a+b;
                }
            }(function(a,b){
                console.log(3);
                console.log("a:",a,"b:",b);
                return a;
            }(1,2)));
        console.log(test(4));
        var test1 = (function(c){
            console.log("c:",c);
            return function(d){
                
                console.log("d:",d,"arguments:",arguments);
                return d;
            };
        }(1));
        console.log(test1(5,7,8)) //d: 5 arguments: [5, 7, 8]
        */
        /*2 这里需要注意 函数变量的提升覆盖 第一个会被覆盖*/
        
        /*var x = 1,y = z = 0;
        function add(n){
            return n=n+3;
        }
        y = add(x);
        function add(n){
            return n=n+1;
        }
        z = add(x);
        console.log(x);    
        console.log(y);    
        console.log(z);    */
        
        /*3 */
        
        function People(){
            this.name = 'Tim';
            this.sayHello = function(){
                console.log('People:'+this.name);
            }
        }
        
        function Man(name){
            this.name = name;
            this.sayHello = function(){
                console.log('Man:'+this.name);
            }
        }
        
        Man.prototype = new People();
        var man = new Man('Jim');
        man.sayHello();
        People.call(man);
        man.sayHello();
        
        </script>

  • 相关阅读:
    HDU 3999 The order of a Tree (排序二叉树的先序遍历)
    如何从 100 亿 URL 中找出相同的 URL?
    Tomcat源码分析 | 一文详解生命周期机制Lifecycle
    SqlSession与SqlSessionFactory到底是什么关系?
    spring boot-jpa整合QueryDSL来简化复杂操作
    EasyExcel读写Excel
    如何将List集合中相同属性的对象合并
    @Data 注解引出的 lombok
    MySQL配置连接
    Django创建
  • 原文地址:https://www.cnblogs.com/moon-yyl/p/9779065.html
Copyright © 2011-2022 走看看