(new Template("")).constructor != Template になってはまる
prototype.js にある Template クラスを使って次のようなコードを書いてたら、ちっとも真にならなくてはまりました。
function showMessage(message, options) { if (message.constructor == Template) { message = message.evaluate(options); } alert(message); }
prototype.js のほうを見ると
Template.prototype = { ... };
という感じになっていて prototype を上書きしていると constructor プロパティが使えなくなるようです。(何が取り出せているんだろう…)
$ js js> var Foo = function() { }; js> (new Foo).constructor == Foo true js> Foo.prototype = { }; [object Object] js> (new Foo).constructor == Foo false js> (new Foo).constructor function Object() { [native code] } js>
Template は Class.create() で生成されているので ↓ のようにして回避。
if (message.initialize == Template.prototype.initialize) { message = message.evaluate(options); }