DRYな備忘録

Don't Repeat Yourself.

モジュールのメソッド存在判定にJSON.stringifyを使っちゃだめ【JavaScript】

JSONじゃないからね

var my = {};
> undefined
my.fnc = function() { window.alert("This is my function"); };
> function () { window.alert("This is my function"); }
my.fnc();
> undefined
JSON.stringify(my.fnc);
> undefined
JSON.stringify(my);
> "{}"

toStringとか使う

my.fnc.toString();
> "function () { window.alert("This is my function"); }"

Don't Repeat Yourself