UNPKG

js-extend

Version:

A simple extend function based on underscore

34 lines (27 loc) 729 B
(function(factory) { if(typeof exports === 'object') { factory(exports); } else { factory(this); } }).call(this, function(root) { var slice = Array.prototype.slice, each = Array.prototype.forEach; var extend = function(obj) { if(typeof obj !== 'object') throw obj + ' is not an object' ; var sources = slice.call(arguments, 1); each.call(sources, function(source) { if(source) { for(var prop in source) { if(typeof source[prop] === 'object' && obj[prop]) { extend.call(obj, obj[prop], source[prop]); } else { obj[prop] = source[prop]; } } } }); return obj; } root.extend = extend; });