ECMAScript 5 strict mode では call(null) がダメな理由
ES5 の仕様読んでるけど "use strict" だと call(null) が使えないってどこに書いてあるのかわからない。
2010-02-17 16:05:37javascript:alert( function(){return this}.call(null) ) がいいかも。
2010-02-17 16:25:01@edvakf strict mode 時の Function.prototype.call 挙動については、仕様の P233 下から4つめのリスト項目に、どのセクションで説明されているかの参照が掲載されてます。あとはそれを追いかければ……。
2010-02-17 16:27:00あれ、でもおかしい、別のところに、thisArg が null or undefined だったら global に置き換えろと書いてあったぞ。
2010-02-17 16:37:08@os0x 58ページの Else if thisArg is null or undefined, set the ThisBinding to the global object. とどう関わってくるのか気になるところです。
2010-02-17 16:38:14あ、58ページに書いてあった。If the function code is strict code, set the ThisBinding to thisArg.
2010-02-17 16:42:00@edvakf そっちはcallでthisを明示してない場合です。良くある無名関数の実行などではthisはglobal objectになります。で、ここがstrictモードではnullです。
2010-02-17 16:42:41call したときはまだ thisArg が null のまま (これは ES3 から変更) だけど、entering function code で strict mode じゃなければ null を global にしろと書いてある。
2010-02-17 16:43:35strict mode なら thisArg をそのまま (global にしたり ToObject したりせずに) ThisBinding すると。
2010-02-17 16:45:31javascript:alert(function(){return this}.call()) は normal mode では window で strict mode だと undefined
2010-02-17 16:46:34@edvakf Function.prototype.callを使っている場合、normal modeでもundefinedになるのでは?
2010-02-17 16:48:51いや、明示してなければならないか。function(){return this}.call()とfunction(){return this}.call(undefined)で違いがでるのかな。うーん。
2010-02-17 16:51:00@os0x 58ページの下のリストを見ていくと、strict なら thisArg をそのまま ThisBinding にして、そうじゃなければ、と続きます。なので normal mode では互換性が保たれます。
2010-02-17 16:53:49@edvakf なるほど、15.3.4.4 Function.prototype.callが呼ぶ13.2.1 [[Call]]のなかで、thisは10.4.3見ろとあるので、そうなりそうです。
2010-02-17 17:10:08