zoukankan      html  css  js  c++  java
  • js小笔记

    1.let ,const,var 区别

          let:块级作用域,if,for,用完就不存在了。

          const:用来定义常量。

          var: 声明的变量在它所声明的整个函数都是可见的。

    2.==和===的区别

          1==true//true

          1===true//false

          1===1//true

         123=='123'//true,类型自动转换了

         123==='123'//false

       != 和 !==同上相似

    3.访问关键字

    obj.for = "Simon"; // 语法错误,因为 for 是一个预留关键字

    obj["for"] = "Simon"; // 工作正常

    4.js中的this关键字,参考https://www.cnblogs.com/lisha-better/p/5684844.html

    function Person() {

    this.age = 0;

    setTimeout(function() {

    console.log(this); //window

    }, 3000);

    }

    var p = new Person();

     

    function Person2() {

    this.age = 0;

    setTimeout(function() {

    console.log(this); //person

    }.bind(this), 3000);

    }

    var p2 = new Person2(); //3秒后返回 person 对象

     

    setTimeout(function() {

    console.log(this); //window

    }, 3000);

    (function() {

    console.log(this) //window

    })()

     

    var obj = {

      i: 10,

      b: () => console.log(this.i, this),

      c: function() {

        console.log( this.i, this)

      }

    }

    //obj.b();  // undefined window{...}

    obj.c(); 

     

    setTimeout(()=>{

    console.log(this)//window

    },1000)

     

    function Person3() {  

        this.age = 0;  

        setInterval(() => {

       

            this.age++;

            console.log(this,this.age)//person

        }, 3000);

    }

    var p = new Person3();

    5.js中的闭包

    6.call ,bind,apply 参考:https://www.cnblogs.com/Shd-Study/archive/2017/03/16/6560808.html

    7.js匿名函数与闭包,参考;https://blog.csdn.net/conatic/article/details/61627183,https://blog.csdn.net/u014470581/article/details/53313396

  • 相关阅读:
    call()与apply()的作用与区别
    Tomcat8/9的catalina.out中文乱码问题解决
    怎样查看Jenkins的版本
    每日日报2020.8.18
    528. Random Pick with Weight
    875. Koko Eating Bananas
    721. Accounts Merge
    515. Find Largest Value in Each Tree Row
    286. Walls and Gates (Solution 1)
    408. Valid Word Abbreviation
  • 原文地址:https://www.cnblogs.com/qiyc/p/9950602.html
Copyright © 2011-2022 走看看