CARVIEW |
Select Language
HTTP/2 200
date: Thu, 24 Jul 2025 15:58:21 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"3fdcf9ab2f9080021da9a06bfbbcb700"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=lD0UWaDUBjfduDGBqDe9uqTShiScNgzzv9UxRpAHvkLZfy635hQ6A1T0OVVm7Ry%2F0wHeV%2B3HTnkoMveb91EtkEBQIdfZLR961tRbDWKV9ZL9sYK7snoPby9k3Ba68ClnEzXf1eP4qfRz7yZVEaibrRyeblYd6MY%2FvqoJtkZgzua78EDlZ54UnM3Y2edAZ36QYLr2%2BXDUsbHziiVKHRgjr1f%2F%2FZU2302wcP9EEr9fwy9kQJ4CnBQtcXVSdy7M0fpW9xg1AAQz1oi20nNEkT%2Bigw%3D%3D--pEq2NEeToJNo3ErH--6uhSGKv0wBIc21OPIyCTww%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1669259102.1753372700; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 15:58:20 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 15:58:20 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: CF4A:3235D2:EAE7E:112A39:6882581C
deep_extend_javascript_objects_underscore_mixin.js · GitHub
Show Gist options
Save wulftone/4712148 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Forked from kurtmilam/deep_extend_javascript_objects_underscore_mixin.js
Created
February 5, 2013 04:23
-
Star
5
(5)
You must be signed in to star a gist -
Fork
2
(2)
You must be signed in to fork a gist
-
Save wulftone/4712148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Based conceptually on the _.extend() function in underscore.js ( see https://documentcloud.github.com/underscore/#extend for more details ) | |
* Copyright (C) 2012 Kurt Milam - https://xioup.com | Source: https://gist.github.com/1868955 | |
* | |
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. | |
**/ | |
deepExtend = function(obj) { | |
var parentRE = /#{\s*?_\s*?}/, | |
slice = Array.prototype.slice, | |
hasOwnProperty = Object.prototype.hasOwnProperty; | |
_.each(slice.call(arguments, 1), function(source) { | |
for (var prop in source) { | |
if (hasOwnProperty.call(source, prop)) { | |
if (_.isUndefined(obj[prop]) || _.isFunction(obj[prop])) { | |
obj[prop] = source[prop]; | |
} | |
else if (_.isString(source[prop]) && parentRE.test(source[prop])) { | |
if (_.isString(obj[prop])) { | |
obj[prop] = source[prop].replace(parentRE, obj[prop]); | |
} | |
} | |
else if (_.isArray(obj[prop]) || _.isArray(source[prop])){ | |
if (!_.isArray(obj[prop]) || !_.isArray(source[prop])){ | |
throw 'Error: Trying to combine an array with a non-array (' + prop + ')'; | |
} else { | |
obj[prop] = _.reject(_.deepExtend(obj[prop], source[prop]), function (item) { return _.isNull(item);}); | |
} | |
} | |
else if (_.isObject(obj[prop]) || _.isObject(source[prop])){ | |
if (!_.isObject(obj[prop]) || !_.isObject(source[prop])){ | |
throw 'Error: Trying to combine an object with a non-object (' + prop + ')'; | |
} else { | |
obj[prop] = _.deepExtend(obj[prop], source[prop]); | |
} | |
} else { | |
obj[prop] = source[prop]; | |
} | |
} | |
} | |
}); | |
return obj; | |
}; | |
/** | |
* Dependency: underscore.js ( https://documentcloud.github.com/underscore/ ) | |
* | |
* Mix it in with underscore.js: | |
* _.mixin({deepExtend: deepExtend}); | |
* | |
* Call it like this: | |
* var myObj = _.deepExtend(grandparent, child, grandchild, greatgrandchild) | |
* | |
* Notes: | |
* Keep it DRY. | |
* This function is especially useful if you're working with JSON config documents. It allows you to create a default | |
* config document with the most common settings, then override those settings for specific cases. It accepts any | |
* number of objects as arguments, giving you fine-grained control over your config document hierarchy. | |
* | |
* Special Features and Considerations: | |
* - parentRE allows you to concatenate strings. example: | |
* var obj = _.deepExtend({url: "www.example.com"}, {url: "https://#{_}/path/to/file.html"}); | |
* console.log(obj.url); | |
* output: "https://www.example.com/path/to/file.html" | |
* | |
* - parentRE also acts as a placeholder, which can be useful when you need to change one value in an array, while | |
* leaving the others untouched. example: | |
* var arr = _.deepExtend([100, {id: 1234}, true, "foo", [250, 500]], | |
* ["#{_}", "#{_}", false, "#{_}", "#{_}"]); | |
* console.log(arr); | |
* output: [100, {id: 1234}, false, "foo", [250, 500]] | |
* | |
* - The previous example can also be written like this: | |
* var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]], | |
* ["#{_}", {}, false, "#{_}", []]); | |
* console.log(arr); | |
* output: [100, {id: 1234}, false, "foo", [250, 500]] | |
* | |
* - And also like this: | |
* var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]], | |
* ["#{_}", {}, false]); | |
* console.log(arr); | |
* output: [100, {id: 1234}, false, "foo", [250, 500]] | |
* | |
* - Array order is important. example: | |
* var arr = _.deepExtend([1, 2, 3, 4], [1, 4, 3, 2]); | |
* console.log(arr); | |
* output: [1, 4, 3, 2] | |
* | |
* - You can remove an array element set in a parent object by setting the same index value to null in a child object. | |
* example: | |
* var obj = _.deepExtend({arr: [1, 2, 3, 4]}, {arr: ["#{_}", null]}); | |
* console.log(obj.arr); | |
* output: [1, 3, 4] | |
* | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
Added support for properties that are functions. Previously it got to the
_.isObject
check and tried to deepExtend it again, which of course is silly if the property is a function, so we need to check forisFunction
before it gets there and take appropriate action.