Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you elaborate why $(document).ready() should not be used?


It's a matter of best practices.

In particular how it's done in this code, where it's outside the definition of the plugin and binding events.

Plugins should be built in a way where it is explicitly invoked by the programmers using them, and the 'proper' way is to invoke them from within a $(document).ready() function that is specified by the user in the order that the user wants.

Lets pretend, for example, that this plugin is invoked from within another $(document).ready(), in which case the document.ready call from within the plugin is completely redundant and useless.


Your points are all valid and I'll consider each one in refactoring the code. Thanks!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: