小编典典

如何比较javascript中的2个函数

javascript

如何比较javascript中的2个函数?我不是在谈论内部参考。说

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

可以比较ab吗?


阅读 270

收藏
2020-05-01

共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( )
2020-05-01