Using $()
returns a jQuery instance. So, you create one instance with this
, and another instance of this
, you have two separate instances. Although they have the same reference to this
, the instances do not match, and this is what is being compared.
This can help get a good example and make things more understandable. jQuery works like a class. So let me use a very simple example where, for example, sake, the $()
function does not exist:
class jQuery { constructor(element) { this.element = element; } } var obj1 = new jQuery(this); var obj2 = new jQuery(this); console.log(obj1 === obj2);
Both of them use the same argument ( this
) to create a new jQuery object. But, again, obj1 is a completely different instance than obj2. They both have their own unique place in memory.
source share