• JavaScript中的this详解


      前  言

     this 

     JavaScript中的this详解

    this详解

      

          This的指向有几种情况?如何人为控制?

    【谁调用this,this指向谁!!】

     

    【this的指向,不关心this写在哪!!只关心包含this的函数,由谁调用!!】

     

    ①   通过()直接调用,this指向window  func();

     

    ②   对象.函数调用,this指向当前对象。 Obj.func()    div.onclick = function(){}

     

    ③   数组下标调用,this指向当前数组   [func,1,2,3]---à arr[0]();

     

    ④   所有内置函数的回调函数,this指向window   setTimeOut(function(){},1000);

     

    人为控制:

    ⑤   通过new关键字调用的,this指向新new出的空对象。   Var obj = new func(){}  this—obj

     

    ⑥   通过call、apply、bind调用,this指向我们规定的对象。

     

      Func.call(obj,参数一,参数2,参数3.。。。)

     

      Func.allply(obj,[ 参数一,参数2,参数3.。。。])

     

      Func.bind(obj)( 参数一,参数2,参数3)   var f = func.bind(obj).   f(…….);

  • 相关阅读:
    假如
    Find the peace with yourself
    Sep 15th 2018
    Sep 10th 2018
    third party sales process 继续说
    成功设置open live writer
    sublime text2 基本配置及结合Python 环境
    Compmgmtlauncher.exe问题解决方法
    nginx 代理服务器
    vmware之linux不重启添加虚拟硬盘
  • 原文地址:https://www.cnblogs.com/zhuanzhibukaixin/p/6848915.html
Copyright © 2020-2023  润新知