$this vs $(this) in jQuery

后端 未结 15 807
北恋
北恋 2020-11-29 18:07

I\'ve seen some discussions on SO regarding $(this) vs $this in jQuery, and they make sense to me. (See discussion here for an example.)

Bu

15条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 18:35

    It's quite simple: $this = $(this). It's just a shorthand used in the scope of the inner function. The dollar sign is just a character in this case, it doesn't refer to jQuery at all. It might just as well have been named _this or xthis, the $ is just a reminder of what the variable contains.

    It may seem pointless, but it eliminates three redundant method invocations (the $() function isn't free) so it is most likely used there for performance reasons.

提交回复
热议问题