Skip to content

Commit bfd34e4

Browse files
committed
removed mutation of prototype object
1 parent 9d2cfc3 commit bfd34e4

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

packages/optimizely-sdk/lib/index.browser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var loggerPlugin = require('./plugins/logger');
2525
var Optimizely = require('./optimizely');
2626
var eventProcessorConfigValidator = require('./utils/event_processor_config_validator');
2727

28-
fns.applyPolyfills();
2928
var logger = logging.getLogger();
3029
logging.setLogHandler(loggerPlugin.createLogger());
3130
logging.setLogLevel(logging.LogLevel.INFO);

packages/optimizely-sdk/lib/utils/fns/index.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,28 @@ var uuid = require('uuid');
1717
var _isFinite = require('lodash/isFinite');
1818
var MAX_NUMBER_LIMIT = Math.pow(2, 53);
1919

20-
// Polyfills for older browsers
21-
var applyPolyfills = function() {
22-
if (typeof Object.assign !== 'function') {
23-
// Must be writable: true, enumerable: false, configurable: true
24-
Object.defineProperty(Object, "assign", {
25-
value: function assign(target) {
26-
'use strict';
27-
if (target === null || target === undefined) {
28-
throw new TypeError('Cannot convert undefined or null to object');
29-
}
30-
var to = Object(target);
31-
for (var index = 1; index < arguments.length; index++) {
32-
var nextSource = arguments[index];
33-
34-
if (nextSource !== null && nextSource !== undefined) {
35-
for (var nextKey in nextSource) {
36-
// Avoid bugs when hasOwnProperty is shadowed
37-
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
38-
to[nextKey] = nextSource[nextKey];
39-
}
20+
module.exports = {
21+
assign: function (target) {
22+
if (!target) {
23+
return {};
24+
}
25+
if (typeof Object.assign === 'function') {
26+
return Object.assign.apply(Object, arguments);
27+
} else {
28+
var to = Object(target);
29+
for (var index = 1; index < arguments.length; index++) {
30+
var nextSource = arguments[index];
31+
if (nextSource !== null && nextSource !== undefined) {
32+
for (var nextKey in nextSource) {
33+
// Avoid bugs when hasOwnProperty is shadowed
34+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
35+
to[nextKey] = nextSource[nextKey];
4036
}
4137
}
4238
}
43-
return to;
44-
},
45-
writable: true,
46-
configurable: true
47-
});
48-
}
49-
}
50-
51-
module.exports = {
52-
assign: function (target) {
53-
// Object.assign crashes if target object is undefined or null
54-
return target ? Object.assign.apply(Object, arguments) : {};
39+
}
40+
return to;
41+
}
5542
},
5643
assignIn: require('lodash/assignIn'),
5744
cloneDeep: require('lodash/cloneDeep'),
@@ -68,7 +55,6 @@ module.exports = {
6855
return uuid.v4();
6956
},
7057
values: require('lodash/values'),
71-
applyPolyfills: applyPolyfills,
7258
isNumber: function(value) {
7359
return typeof value === 'number';
7460
},

0 commit comments

Comments
 (0)