Last active
October 25, 2017 06:04
-
-
Save jonjaques/3036701 to your computer and use it in GitHub Desktop.
Revisions
-
jonjaques revised this gist
Dec 10, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -89,7 +89,7 @@ clone = src && isPlainObject(src) ? src : {}; } // Never move original objects, clone them target[ name ] = extend( deep, clone, copy ); // Don't bring in undefined values } else if ( copy !== undefined ) { -
jonjaques renamed this gist
Jan 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jonjaques revised this gist
Mar 20, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ return type(obj) === "array"; } // Make this public function extend() { var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, @@ -103,5 +103,5 @@ return target; }; return global.__extend = extend; })(window); -
jonjaques revised this gist
Mar 20, 2013 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ (function(global, undefined) { function type(obj) { var checker = {}; var types = "Boolean Number String Function Array Date RegExp Object".split(" "); for(var i in types){ @@ -9,13 +9,13 @@ String( obj ) : checker[ Object.prototype.toString.call(obj) ] || "object"; } function isFunction(obj) { return type(obj) === "function"; } function isWindow(obj) { return obj != null && obj == obj.window; } function isPlainObject(obj) { var hasOwn = Object.prototype.hasOwnProperty; // Must be an Object. // Because of IE, we also have to check the presence of the constructor property. @@ -103,5 +103,5 @@ return target; }; return global.__extend = this.extend; })(window); -
jonjaques revised this gist
Mar 19, 2013 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ function myFunction(opts) { var defaults = { param1: 'foo', param2: 'bar' }; var options = __extend(defaults, opts); return options; } myFunction({param2: 'baz'}); // { param1: 'foo', param2: 'baz' } -
jonjaques revised this gist
Mar 19, 2013 . 2 changed files with 3 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ (function Extender(){ function type(obj){ var checker = {}; var types = "Boolean Number String Function Array Date RegExp Object".split(" "); @@ -103,5 +103,5 @@ function Extender(){ return target; }; return window.__extend = this.extend; })(); -
jonjaques revised this gist
Nov 6, 2012 . 2 changed files with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Use it like this var ___extend = new Extender(); var newObj = ___extend(orig, diff); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,3 @@ function Extender(){ function type(obj){ var checker = {}; @@ -109,4 +104,4 @@ function Extender(){ }; return this.extend; } -
jonjaques revised this gist
Nov 6, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -107,4 +107,6 @@ function Extender(){ // Return the modified object return target; }; return this.extend; } -
jonjaques revised this gist
Jul 3, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // Use it like this var ext = new Extender(); var newObj = ext.extend(orig, diff); function Extender(){ function type(obj){ -
jonjaques created this gist
Jul 3, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,110 @@ // Use it like this var ext = new Extender(); new newObj = ext.extend(orig, diff); function Extender(){ function type(obj){ var checker = {}; var types = "Boolean Number String Function Array Date RegExp Object".split(" "); for(var i in types){ checker[ "[object " + types[i] + "]" ] = types[i].toLowerCase(); } return obj == null ? String( obj ) : checker[ Object.prototype.toString.call(obj) ] || "object"; } function isFunction(obj){ return type(obj) === "function"; } function isWindow(obj){ return obj != null && obj == obj.window; } function isPlainObject( obj ) { var hasOwn = Object.prototype.hasOwnProperty; // Must be an Object. // Because of IE, we also have to check the presence of the constructor property. // Make sure that DOM nodes and window objects don't pass through, as well if ( !obj || type(obj) !== "object" || obj.nodeType || isWindow( obj ) ) { return false; } try { // Not own constructor property must be Object if ( obj.constructor && !hasOwn.call(obj, "constructor") && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { return false; } } catch ( e ) { // IE8,9 Will throw exceptions on certain host objects #9897 return false; } // Own properties are enumerated firstly, so to speed up, // if last one is own, then all properties are own. var key; for ( key in obj ) {} return key === undefined || hasOwn.call( obj, key ); } function isArray(obj){ return type(obj) === "array"; } // Make this public this.extend = function() { var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; // Handle a deep copy situation if ( typeof target === "boolean" ) { deep = target; target = arguments[1] || {}; // skip the boolean and the target i = 2; } // Handle case when target is a string or something (possible in deep copy) if ( typeof target !== "object" && !isFunction(target) ) { target = {}; } for ( ; i < length; i++ ) { // Only deal with non-null/undefined values if ( (options = arguments[ i ]) != null ) { // Extend the base object for ( name in options ) { src = target[ name ]; copy = options[ name ]; // Prevent never-ending loop if ( target === copy ) { continue; } // Recurse if we're merging plain objects or arrays if ( deep && copy && ( isPlainObject(copy) || (copyIsArray = isArray(copy)) ) ) { if ( copyIsArray ) { copyIsArray = false; clone = src && isArray(src) ? src : []; } else { clone = src && isPlainObject(src) ? src : {}; } // Never move original objects, clone them target[ name ] = this.extend( deep, clone, copy ); // Don't bring in undefined values } else if ( copy !== undefined ) { target[ name ] = copy; } } } } // Return the modified object return target; }; }