Pycharmのjavascriptエディタでthisがglobal objectを指している場合は警告がでる


こんな警告がでてて、どういうことなのかと思ってみてみたら、thisがglobal objectを指している場合は警告をだすようになっていた。



とくに問題はないと思うのでとりあえず、設定をoffにしておいた。


ちなみに

上記のコードでは、thisを渡さなくても、即時関数内でのthisはglobal objectを指しているはず。

(function(){
    this.location.href  // <- thisはglobal object
}).call();

だけど、"use strict"になった場合は関数内のthisはundefinedになる。

"use strict"

(function(){
    this.location.href  // <- thisがundefined なのでエラー
}).call();

callにthisを渡しておけば"use strict"でも動く

"use strict"

(function(){
    this.location.href  // <- thisはglobal object
}).call(this);