Ticket #12212 (closed enhancement: invalid)
Document that $.extend will ignore null/undefined arguments
| Reported by: | T.J. Crowder <tj@…> | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.8rc1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
This is a fairly common pattern for setting options, even if options isn't provided:
function doSomethingCool(options) {
options = $.extend(true, {}, defaultOptions, options);
// ...
}
...but it relies on the behavior that $.extend will ignore the options argument if it's null or undefined. $.extend does indeed do that, and on purpose (with a comment, even), but it's not documented.
Recommend documenting it by adding this text:
In the arguments list, null and undefined objectN arguments are skipped (they do not cause an error). For example, this works even if the options variable is undefined or null:
options = $.extend(true, {}, defaultOptions, options);
...just before the paragraph starting with "On a deep extend..." near the end.
Change History
comment:1 follow-up: ↓ 2 Changed 9 months ago by dmethvin
- Keywords needsdocs added
- Status changed from new to closed
- Resolution set to invalid
comment:2 in reply to: ↑ 1 Changed 9 months ago by T.J. Crowder <tj@…>
Replying to dmethvin:
closing invalid but marking as needsdocs
For future reference, is there a better way to log documentation tickets?
Thanks,
-- T.J.
comment:3 Changed 9 months ago by scott.gonzalez
https://github.com/jquery/api.jquery.com/issues (the new site hasn't launched yet).
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

closing invalid but marking as needsdocs