70 votes

comment comparer 2 fonctions en javascript

Comment comparer 2 fonctions en javascript ? Je ne parle pas de référence interne. Dire

Est-il possible de comparer et ?

69voto

Rony SP Points 1564
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( )  

0voto

Wenfang Points 45

Solution propre ES6+ utilisant des littéraux de modèle:

Signifie fondamentalement:

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X