Skip to content

Commit

Permalink
feat(reflect): add polyfill for defineProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktim committed Apr 20, 2016
1 parent c2c98c0 commit c6fbc90
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/reflect.js
Expand Up @@ -32,6 +32,20 @@ if (typeof Reflect.metadata !== 'function') {
};
}

if (typeof Reflect.defineProperty !== 'function') {
Reflect.defineProperty = function(target, propertyKey, descriptor) {
if (typeof target !== 'object') {
throw new TypeError('Reflect.defineProperty called on non-object');
}
try {
Object.defineProperty(target, propertyKey, descriptor);
return true;
} catch (e) {
return false;
}
};
}

if (typeof Reflect.construct !== 'function') {
Reflect.construct = function(Target, args) {
if (args) {
Expand All @@ -48,4 +62,4 @@ if (typeof Reflect.construct !== 'function') {
a.push.apply(a, args);
return new (bind.apply(Target, a));
};
}
}

0 comments on commit c6fbc90

Please sign in to comment.