JavaScriptで2つの関数を比較するにはどうすればいいですか?質問する

JavaScriptで2つの関数を比較するにはどうすればいいですか?質問する

JavaScriptで2つの関数を比較するにはどうすればいいでしょうか?内部参照の話ではありません。

var a = function(){return 1;};
var b = function(){return 1;};

aと を比較することは可能ですかb?

ベストアンサー1

var a = b = function( c ){ return c; };
//here, you can use a === b because they're pointing to the same memory and they're the same type

var a = function( c ){ return c; },
    b = function( c ){ return c; };
//here you can use that byte-saver Andy E used (which is implicitly converting the function to it's body's text as a String),

''+a == ''+b.

//this is the gist of what is happening behind the scences:

a.toString( ) == b.toString( )  

おすすめ記事