Object.toSource パッチ
via http://d.hatena.ne.jp/holidays-l/20071127/p1
こんなところであれですが、トラックバックもらったついでにご報告です。
とりあえず IE と自前の JScript シェルでしか試してないのですが、オブジェクトと配列のときにうまく動いてないように思えます。
d:\scripts\js\ijscript>cscript //nologo ijsc.js ijsc> load('http://svn.coderepos.org/share/lang/javascript/Object.toSource/lib/Object/toSource.js') ijsc> ([1,2,3]).toSource() TypeError: 型が一致しません。 ijsc> ({x:1,y:2}).toSource() () ijsc> quit()
で、パッチです。
Index: toSource.js =================================================================== --- toSource.js (revision 2075) +++ toSource.js (working copy) @@ -58,9 +58,9 @@ } if (!(this instanceof Array) && this instanceof Object) { - return '(' + toSource() + ')'; + return '(' + toSource.apply(this) + ')'; } - return toSource(); + return toSource.apply(this); }; Object.prototype.toSource = toSourceFirst;
で、確認。
d:\scripts\js\ijscript>cscript //nologo ijsc.js ijsc> load('tosource.js') ijsc> ([1,2,3]).toSource() [(new Number(1)), (new Number(2)), (new Number(3))] ijsc> ({x:1,y:2}).toSource() ({x:(new Number(1)), y:(new Number(2))}) ijsc> quit() d:\scripts\js\ijscript>