Why “$().ready(handler)” is not recommended?

后端 未结 6 1554
鱼传尺愫
鱼传尺愫 2020-11-27 13:30

From the jQuery API docs site for ready

All three of the following syntaxes are equivalent:

  • $(document).ready(handle
6条回答
  •  盖世英雄少女心
    2020-11-27 14:26

    More than likely this is just a documentation bug and should be fixed, the only downside to using $().ready(handler) is it's readability. Sure, argue that $(handler) is just as unreadable. I agree, that's why I don't use it.

    You can also argue that one method is faster than another. However, how often do you call this method enough times in a row on a single page to notice a difference?

    Ultimately it comes down to personal preference. There is no downside to using $().ready(handler) other than the readability argument. I think the documentation is miss-leading in this case.

提交回复
热议问题