Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#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:
Blocked by: Blocking:

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 (4)

comment:1 Changed 7 years ago by dmethvin

Keywords: needsdocs added
Resolution: invalid
Status: newclosed

closing invalid but marking as needsdocs

comment:2 in reply to:  1 Changed 7 years 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 7 years ago by scottgonzalez

https://github.com/jquery/api.jquery.com/issues (the new site hasn't launched yet).

comment:4 Changed 6 years ago by mikesherov

Keywords: needsdocs removed
Summary: Document that $.extend will ignore null/undefined arguments.Document that $.extend will ignore null/undefined arguments
Note: See TracTickets for help on using tickets.