While comparing functions in Javascript, am thinking that it compares the memory at which function is defined to cross-check that the given 2 functions are equal.
So, was trying to compare a member function by accessing it from 2 different instances of same object as below:
function testFn(name) {
var name = name;
var self = this;
self.compareFn = function() {
console.info(name);
}
}
var fn1 = new testFn('fn1');
var fn2 = new testFn('fn2');
console.info(fn1.compareFn == fn2.compareFn); //Returns false
Have defined an object testFn with one member function ("compareFn") and created 2 instances of it (fn1,fn2) and but on comparing "fn1.compareFn == fn2.compareFn
",it fails.
Remember, that member function is shared across multiple instances and only local variables will be allocated separately.
Please suggest why this comparison fails.