Skip to main content

Bug Tracker

Side navigation

#12212 closed enhancement (invalid)

Opened August 07, 2012 01:47PM UTC

Closed August 21, 2012 01:31AM UTC

Last modified October 15, 2012 07:47PM UTC

Document that $.extend will ignore null/undefined arguments

Reported by: T.J. Crowder <tj@crowdersoftware.com> 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.

Attachments (0)
Change History (4)

Changed August 21, 2012 01:31AM UTC by dmethvin comment:1

keywords: → needsdocs
resolution: → invalid
status: newclosed

closing invalid but marking as needsdocs

Changed August 21, 2012 07:27AM UTC by T.J. Crowder <tj@crowdersoftware.com> comment:2

Replying to [comment:1 dmethvin]:

closing invalid but marking as needsdocs

For future reference, is there a better way to log documentation tickets?

Thanks,

-- T.J.

Changed August 21, 2012 12:20PM UTC by scottgonzalez comment:3

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

Changed October 15, 2012 07:47PM UTC by mikesherov comment:4

keywords: needsdocs
summary: Document that $.extend will ignore null/undefined arguments.Document that $.extend will ignore null/undefined arguments