Possible improvements in WordPress core JavaScript - Yoast/wordpress-develop-mirror GitHub Wiki

This is a list of code smells that could be improved to make the code more readable.

src/wp-admin/js/tags.js

  • Callback hell. Solution: Refactor functions into named functions.
  • data.match(/tag_ID=(\d+)/)[1] should be extracted to a variable called term_id.

src/wp-includes/js/heartbeat.js

  • interval is currently both a getter and a setter. It would be better to split this into a proper getter and setter.

src/js/_enqueues/lib/admin-bar.js

  • Keycodes are magic numbers and should be abstracted to ENTER variables. (Maybe find those in all of WordPress so keycodes become easier in general.)
  • Variable names (while ( t && t != aB && t != d ) {).

src/js/_enqueues/wp/emoji.js

  • Node types are magic numbers and should be abstracted to a NODE_TYPE_TEXT_NODE variable.