zoukankan      html  css  js  c++  java
  • 小议Javascript中的this指针

                                 小议Javascript中的this指针

    (1) 在全局执行环境中使用this,标识Global对象,在浏览器中就是window对象。

    (2)当在函数执行环境中使用this时,如果函数没有明显的作为非window对象的属性,而是只是定义了函数,不管这个函数是不是定义在另一个函数中,这个函数中的this仍然标识window对象。如果函数显示地作为一个非window对象的属性,那么函数中的this就代表这个对象。

    var o=new Object;
    o.func=function()
    {
        alert((this===o));
        (function(){
            alert((this===window));
        }
        )();
    }
    o.func();

    (3) 当通过new运算符来调用函数时,函数被当作一个构造函数,this指向构造函数创建出来的对象。

  • 相关阅读:
    网络系列之
    网络系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
  • 原文地址:https://www.cnblogs.com/xpxu/p/1689067.html
Copyright © 2011-2022 走看看