Skip to content

Instantly share code, notes, and snippets.

@spiralx
Created July 6, 2015 17:31
Show Gist options
  • Select an option

  • Save spiralx/68cf40d7010d829340cb to your computer and use it in GitHub Desktop.

Select an option

Save spiralx/68cf40d7010d829340cb to your computer and use it in GitHub Desktop.

Revisions

  1. spiralx created this gist Jul 6, 2015.
    32 changes: 32 additions & 0 deletions object-assign.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    if (!Object.assign) {
    Object.defineProperty(Object, 'assign', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(target) {
    'use strict';
    if (target === undefined || target === null) {
    throw new TypeError('Cannot convert first argument to object');
    }

    var to = Object(target);
    for (var i = 1; i < arguments.length; i++) {
    var nextSource = arguments[i];
    if (nextSource === undefined || nextSource === null) {
    continue;
    }
    nextSource = Object(nextSource);

    var keysArray = Object.keys(Object(nextSource));
    for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
    var nextKey = keysArray[nextIndex];
    var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
    if (desc !== undefined && desc.enumerable) {
    to[nextKey] = nextSource[nextKey];
    }
    }
    }
    return to;
    }
    });
    }