When the last part of expression will be returned
I have the following expression taken from jQuery native code:
handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || []
I'm curios under which conditions the last part of the expression - [] -
will be assigned to the handlers variable? Here is my speculation:
1) This part is executed first ( jQuery._data( this, "events" ) || {} ).
If there are no attached events jQuery._data( this, "events" ) ===
undefined, then the empty object is returned.
2) Then this part {}[event.type] || [] is processed. If event.type is
undefined, then an array is returned and assigned to the handlers
variable. So it means that for the array to be returned it is enough that
event.type is undefined?
Am I right?
No comments:
Post a Comment