gpt4 book ai didi

javascript - 我如何比较javascript中的2个函数

转载 作者:IT王子 更新时间:2023-10-29 03:03:32 24 4
gpt4 key购买 nike

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

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

是否可以比较 ab

最佳答案

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 - 我如何比较javascript中的2个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9817629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com