型システムが弱いと何が起こっているのか把握するのが難しい
JavaScriptで文字列にメソッドを追加。
String.prototype.getThisVar = function () { return this; }; var s = "hello"; document.write((s.getThisVar() == s) + "<br>"); // ture document.write((s.getThisVar() === s) + "<br>"); // false
なにぃ? thisの値が違うだと?
俺は何か大きな勘違いをしていたのかもしれない。
追記(2013-09-08)
プリミティブ型をオブジェクト扱いすると、一時的にオブジェクトが生成されて、実行されたあとに破棄されるって「メンテナブルJavaScript」書いてあった。
var s = "hello"; s.num = 123; console.log(s.num); // undefined
へぇ~