The judgment of two anonymous functions is not equal.

problem description


I have written two function with the same method body in two different vue components, and they all have the same scope except that they define different scopes, so how can I tell that they are different? Or whether they can get their scope

the environmental background of the problems and what methods you have tried

I tried to encode the method with MD5 to get the id in the figure, but this id is the same.


compare function references directly

var a=function(){}
var b=function(){}
console.log(a===b)

provides an idea: convert a function to a string and then compare it. The
function test (args) {console.log (args)};
function test.toString (); is "function test (args) {console.log (args)}".
compares the values that two functions convert to strings, and if they are equal, the two functions are the same.


do you mean to judge that the scope of these two identical functions is different?
many methods because js is lexical scope, in fact, their scope is the declared location
method 1:
two vue files have a global variable but a different value
and then directly return the global variable in the function method. See if it is the same
method 2:
return this directly in the function

Menu