Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在纯javascript的严格模式下使用此关键字_Javascript_Strict - Fatal编程技术网

在纯javascript的严格模式下使用此关键字

在纯javascript的严格模式下使用此关键字,javascript,strict,Javascript,Strict,我试图在函数中使用“this”关键字,这是可行的 var test = function(){ console.log(this); //console logs the window object } (function(){ test(); }); 但是,当我尝试使用严格模式时,这是未定义的 'use strict'; var test = function(){ console.log(this); //undefined } (function(){ t

我试图在函数中使用“this”关键字,这是可行的

var test = function(){
    console.log(this); //console logs the window object
}
(function(){
    test();
});
但是,当我尝试使用严格模式时,这是未定义的

'use strict';
var test = function(){
    console.log(this); //undefined
}
(function(){
    test();
});
我想知道是否有可能在严格模式下从内部函数访问this关键字

非常感谢您的帮助

所以对于任何面临同样问题的人来说 这很有效

'use strict';
var test = {
    fname:'kalesh',
    check: function(){
        console.log(this.fname);
    }
};
(function(){
    test.check();
})();

在严格模式下,似乎必须在对象内部才能使用此关键字,而不仅仅是在函数内部

如果您只想将窗口对象应用于此,可以使用
调用(窗口)
应用(窗口)

适用于:


呼叫:

不是我要找的,但你的链接将我指向了正确的asnwer