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

后端 未结 6 1538
鱼传尺愫
鱼传尺愫 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:25

    I would say its simply the fact that $() returns an empty object whereas $(document) does not so your applying ready() to different things; it still works, but I would say its not intuitive.

    $(document).ready(function(){}).prop("title") // the title
    $().ready(function(){}).prop("title")  //null - no backing document
    

提交回复
热议问题