Take the 2-minute tour ×
English Language & Usage Stack Exchange is a question and answer site for linguists, etymologists, and serious English language enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
1  
Hmm. How much code can go in "a function"? It's even more meaningless than "How long is a piece of string?", given that most functions call other, lower-level, functions. How much code is "in" the main() function of a C/C++ program? I think this is not a constructive question about English. –  FumbleFingers Feb 5 '12 at 16:23
add comment

3 Answers

up vote 10 down vote accepted

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)
share|improve this answer
1  
Don't spoil the ship for a ha'p'orth of tar. –  MετάEd Feb 3 '12 at 19:37
add comment

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.

share|improve this answer
add comment

"a function's worth of code" refers to code inside a "function".

share|improve this answer
    
No, unfortunately, it's not. –  Kris Dec 28 '13 at 9:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.