我如何比较 javascript 中的 2 个函数 [英] how do I compare 2 functions in javascript
本文介绍了我如何比较 javascript 中的 2 个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较 javascript 中的 2 个函数?我不是在谈论内部参考.说
How do I compare 2 functions in javascript? I am not talking about internal reference. Say
var a = function(){return 1;};
var b = function(){return 1;};
是否可以比较 a
和 b
?
Is it possible to compare a
and b
?
推荐答案
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( )
这篇关于我如何比较 javascript 中的 2 个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文