Skip to content

Commit

Permalink
refactor(assign): add Object.assign polyfill util
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Jan 13, 2016
1 parent fbe726d commit 8f5ef62
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/util/assign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {root} from './root';

const Object = root.Object;

if (typeof (<any>Object).assign != 'function') {
(function () {
(<any>Object).assign = function assignPolyfill(target: Object, ...sources: Array<Object>): Object {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}

const output = Object(target);
const len = sources.length;
for (let index = 0; index < len; index++) {
let source = sources[index];
if (source !== undefined && source !== null) {
for (let key in source) {
if (source.hasOwnProperty(key)) {
output[key] = source[key];
}
}
}
}

return output;
};
})();
}

export const assign: (target: Object, ...sources: Array<Object>) => Object = Object.assign;

0 comments on commit 8f5ef62

Please sign in to comment.