UNPKG

fabric-pure-browser

Version:

Fabric.js package with no node-specific dependencies (node-canvas, jsdom). The project is published once a day (in case if a new version appears) from 'master' branch of https://github.com/fabricjs/fabric.js repository. You can keep original imports in

70 lines (66 loc) 2.26 kB
(function() { /** * Copies all enumerable properties of one js object to another * this does not and cannot compete with generic utils. * Does not clone or extend fabric.Object subclasses. * This is mostly for internal use and has extra handling for fabricJS objects * it skips the canvas property in deep cloning. * @memberOf fabric.util.object * @param {Object} destination Where to copy to * @param {Object} source Where to copy from * @return {Object} */ function extend(destination, source, deep) { // JScript DontEnum bug is not taken care of // the deep clone is for internal use, is not meant to avoid // javascript traps or cloning html element or self referenced objects. if (deep) { if (!fabric.isLikelyNode && source instanceof Element) { // avoid cloning deep images, canvases, destination = source; } else if (source instanceof Array) { destination = []; for (var i = 0, len = source.length; i < len; i++) { destination[i] = extend({ }, source[i], deep); } } else if (source && typeof source === 'object') { for (var property in source) { if (property === 'canvas') { destination[property] = extend({ }, source[property]); } else if (source.hasOwnProperty(property)) { destination[property] = extend({ }, source[property], deep); } } } else { // this sounds odd for an extend but is ok for recursive use destination = source; } } else { for (var property in source) { destination[property] = source[property]; } } return destination; } /** * Creates an empty object and copies all enumerable properties of another object to it * @memberOf fabric.util.object * TODO: this function return an empty object if you try to clone null * @param {Object} object Object to clone * @return {Object} */ function clone(object, deep) { return extend({ }, object, deep); } /** @namespace fabric.util.object */ fabric.util.object = { extend: extend, clone: clone }; fabric.util.object.extend(fabric.util, fabric.Observable); })();