• js 函数与类的区别


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    </body>
    <script>
    
        function show() {
    
            console.log(this)
        }
    
        show(); //window object
        new show(); //object
    
    
    
        j = {
            name:'ldq',
            age:18,
            info:function () {
                console.log(`我的名字是${name},我的年龄是${age}`)
                console.log(123)
            }
        };
        console.log(j);
        new j.info();
    
    
    
        function show(name,age) {
            //系统偷偷替我们做了
    //        var this = new object();
    
            this.name = name;
            this.age = age;
            this.fun1=function () {
                console.log(`我的名字是${this.name},我的年龄是${this.age}`)
    
                // /系统偷偷替我们做了
    //            return this
    
            }
        }
        obj = new show('ldq',18)
        obj.fun1()
    </script>
    </html>
  • 相关阅读:
    Luogu 三国游戏
    牛客练习赛60E
    cf1321E
    cf988D
    cf1089F
    cf1055C
    cf997B
    cf1033D
    cf1062D
    cf1081E
  • 原文地址:https://www.cnblogs.com/ldq1996/p/8371073.html
Copyright © 2020-2023  润新知