Perlの話ではない、JavaScriptの話なのである。
あと、タイトルはまんじゅう怖い的な意味なのである
Firefox4.0b10pre に ECMAScript5 の Strict モードが実装されましたーパチパチー
で、自分がはまった罠について書いておくよ。まあ上記ページに書かれていることなんだけどね。
"caller", "callee" in arguments オブジェクト
使うとエラー
(function() {
"use strict";
return arguments.callee;
})();
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
arguments.caleeはイベントリスナ関係で使うことが多いので辛い><
予約語を使うとエラー
まあ当然なんだけど、将来のために予約されている単語もNG。
(function() {
"use strict";
var class = "hoge";
})();
SyntaxError: class is a reserved identifier
もちろん、変数じゃなくて関数だって同じだぞ。
因みに将来のために予約されている単語は以下のとおり
- class
- enum
- extends
- super
- const
- export
- import
仕方ないので、_classと頭にアンダーバーを付けて回避。
8進数つかうとエラー
(function() {
"use strict";
var num = 0755;
})();
SyntaxError: octal literals and octal escape sequences are deprecated
XPCOMとかでファイルやディレクトリを作成するときのパーミッションに0755を使ったりするので、地味に痛い。仕方ないので、parseInt("0755", 8)で回避
今のところ、こんな感じかな。