zoukankan      html  css  js  c++  java
  • 匿名函数普通函数和构造函数

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>函数简单分类</title>
    </head>

    <body>
        <script>
            //首先,我们用function关键字创建一个函数,然后执行
            //demo1
            // console.log();
            // function f1() {              //普通函数
            //     console.log(this);
            // }
            // // f1 = 0;               //在堆内存创建一块内存空间,存储整个函数代码,然后在栈内存中存储变量f1,f1存储的是函数代码
            // f1();                    //的内存地址,所以f1重新赋值为0会返回错误,f1()是把函数字符串代码变为js代码执行,this指向window

            //demo2
            // var a = function () {
            //     a = 1;
            //     console.log(a);        
            // }
            // a();
            // a();                     //匿名函数,此函数没执行之前a=函数体的字符串,执行之后a=1;所以第一个能运行,第二个报错

            //demo3 
            // function F1(names, ages) {             //构造函数
            //     this.name = names;
            //     this.age = ages;
            //     this.eat = function () {
            //         console.log(this);             //this指向的是F1的实例化对象,下面的就是obj
            //     }
            // }
            // var obj = new F1("隔壁老王", 100)
            // obj.eat()                  
        </script>
    </body>

    </html>
    如有错误,欢迎指正
  • 相关阅读:
    NYOJ:喷水装置(一)
    NYOJ:QQ农场
    NYOJ:死神来了(鸽巢定理)
    NYOJ:星际之门(一)(cayley定理)
    计蒜客: 法师康的工人 (贪心)
    '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "AttentionController" nib but the view outlet was not set.'
    UITabBar 蓝色
    App installation failed There was an internal API error.
    UIImage将图片写入本地相册
    UINavigationItem不显示
  • 原文地址:https://www.cnblogs.com/simadoudou/p/12383795.html
Copyright © 2011-2022 走看看