您好,欢迎来到知库网。
搜索
您的当前位置:首页javascript.this

javascript.this

来源:知库网
var strict = (fuction(){return !this; }());

this 是一个关键字不是变量,也不是属性名;js不允许给this赋值。
关键字this 没有作用域的限制;嵌套函数不会从调用它的函数中继承this!
如果嵌套函数作为方法调用,this的值指向调用它的对象
如果嵌套函数作为函数调用,其this值不是全局对象就是undefined(use strict;)
例子:

var o ={
    m:function(){
        var self = this;
        console.log(self === o);
        f();
        function f(){
            console.log(this === o);
            console.log(self === o);
        }
    }
}
o.m();
/**
    true
    false
    true
*/

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务