Why are jQuery's callback arguments inconsistent?

后端 未结 4 1104
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 07:21

A common pattern within jQuery is a method that takes a callback which is passed an element of an array and its index within that array. However, it seems completely random

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 08:12

    Since Javascript lets you ignore parameters that you aren't using (i.e., you can define a callback function which takes only one parameter, even if it will be called with two), generally, the first parameter is the one you are mostly likely to be using. (Actually, the this varaible is usually the data item you'r most likely to use, followed by the first parameter, etc)

提交回复
热议问题