unsafeWindow についてしらべてみた

昨日書いてたグリモンを参考にしたIEスクリプト

var w = typeof unsafeWindow != 'undefined' ? unsafeWindow : window;

の意味が理解できてなかったので、改めて調べてた。

式の内容としては、unsafeWindowがあるかないかを評価して、在るならunsafeWIndowを var w に
無いならwindows を var w に代入っていう操作なんだけど、

そもそもunsafeWindowってなんやねん??って話。

グリモンのページ元を参照してみると。。。

Sometimes, you will want to access the global variables in the content document. For example, maybe the content document defines a function which you want to call. In these cases, you can access the content document's global scope with the unsafeWindow variable. Just be aware that accessing the members of this variable means that content scripts can detect your script and potentially interfere with it if they choose.

greasemonkey Writing User Scripts

とあるように、
unsafeWindowはグリモン特有のオブジェクトで、
参照しているページ(みているWebサイト)のwindowオブジェクトを参照したい場合に利用するらしい。


I See!!!


まあ、#include stdio.h みたいなもんで、グリモンのおまじないと考えていい(よね??)。
グリモンでは参照ページのオブジェクトにアクセスするにはunsafeWindowをつかって、
他のスクリプトではunsafeWindowがないからwindow使えばいいという考えでおk?

でも、グリモンスクリプトを他に移植されるという考えでスクリプト書かない限り、
いらないとおもうんですけど。。。と言ってみるテスト。

あとは、この辺参考にした