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

  • 相关阅读:
    Asp.Net MVC 路由
    Http 请求处理流程
    Http Module 介绍
    彻底屏蔽鼠标右键、另存为、查看源文件
    使用TransactionScope实现单数据库连接事务操作
    Asp.Net MVC(创建一个任务列表应用程序) Part.1
    Http Handler 介绍
    jQuery.API源码深入剖析以及应用实现(1) - 核心函数篇
    安装MSSQL2008出现的问题记录
    SQL – 8.Union
  • 原文地址:https://www.cnblogs.com/qiyc/p/9950602.html
Copyright © 2011-2022 走看看