Meaning of "a function's worth of code"

We have already seen how to make jQuery react to the loading of a web page. The $(document).ready() event handler can be used to fire off a function's worth of code, but there's a bit more to be said about it.

What's the meaning of "a function's worth of code" in the above context?


In general, a phrase of the form "An X's worth of Y" refers to some quantity of Y that fills a container of size X.

Examples:

  • A year's worth of savings (all the savings you would save in a year's time)
  • A bottle's worth of champagne (enough champagne to fill a bottle)
  • A function's worth of code (enough code that it should be separated into a function)

The literal meaning of "a function's worth of code" is "enough code for a function", that is, not so small an amount of code that it should be inlined, nor so large an amount that it should be refactored into multiple functions.

However, in the given context the amount of code really is not the issue: the important point is that a callback event handler is a single function, and if multiple functions are to be called for a single event, either the single handler must call them in turn, or a queue of functions must be maintained by the system. The $(document).ready() method supports a queue mechanism, which presumably is what the paragraph you gave is building up to.