Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript variables, What does var x = a = {} do?

I see in jQuery something like this:

jQuery.fn = jQuery.prototype = {}

Why is this being done? Isn't this the same thing just saying jQuery.prototype = {}? I'm not sure I understand what Resig is accomplishing here.


2 Answers

The same as:

jQuery.prototype = {}
jQuery.fn = jQuery.prototype

In my opinion having all in one line makes more clear that your assigning the same value to both variables

like image 106
victor hugo Avatar answered Aug 22 '26 17:08

victor hugo


This is equivalent to:

jQuery.prototype = {}
jQuery.fn = jQuery.prototype

In other words jQuery.fn and jQuery.prototype both point to the same object.

like image 38
Kevin Loney Avatar answered Aug 22 '26 19:08

Kevin Loney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!