MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / mixin

Function mixin

public/javascripts/require.js:107–126  ·  view source on GitHub ↗

* Simple function to mix in properties from source into target, * but only if target does not already have a property of the same name.

(target, source, force, deepStringMixin)

Source from the content-addressed store, hash-verified

105 * but only if target does not already have a property of the same name.
106 */
107 function mixin(target, source, force, deepStringMixin) {
108 if (source) {
109 eachProp(source, function (value, prop) {
110 if (force || !hasProp(target, prop)) {
111 if (deepStringMixin && typeof value === 'object' && value &&
112 !isArray(value) && !isFunction(value) &&
113 !(value instanceof RegExp)) {
114
115 if (!target[prop]) {
116 target[prop] = {};
117 }
118 mixin(target[prop], value, force, deepStringMixin);
119 } else {
120 target[prop] = value;
121 }
122 }
123 });
124 }
125 return target;
126 }
127
128 //Similar to Function.prototype.bind, but the 'this' object is specified
129 //first, since it is easier to read/figure out what 'this' will be.

Callers 1

newContextFunction · 0.70

Calls 4

eachPropFunction · 0.85
hasPropFunction · 0.85
isArrayFunction · 0.85
isFunctionFunction · 0.85

Tested by

no test coverage detected