I would like to assign some object to a target object by Javascript Object.assign(). It works fine in chrome. In safari though I get an error.
TypeError: 'undefined' is not a function (evaluating 'Object.assign(wkObj,tObj,list)')
Object
var list = {'width':'100px'};
var tz = "translateZ(-18px)";
var tObj = {'transform': tz};
var wkObj = {'-webkit-transform': tz};
I would like to assign some object to a target object by Javascript Object.assign(). It works fine in chrome. In safari though I get an error.
TypeError: 'undefined' is not a function (evaluating 'Object.assign(wkObj,tObj,list)')
Object
var list = {'width':'100px'};
var tz = "translateZ(-18px)";
var tObj = {'transform': tz};
var wkObj = {'-webkit-transform': tz};
Share
Improve this question
asked Sep 5, 2016 at 8:49
duskdeepduskdeep
452 silver badges4 bronze badges
1
- 1 it is not supported developer.mozilla/it/docs/Web/JavaScript/Reference/… you could use the suggested polyfill – invernomuto Commented Sep 5, 2016 at 8:53
1 Answer
Reset to default 5It's not supported by safari, but you can always create a polyfill:
if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: function(target, firstSource) {
'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;
}
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;
}
});
}
Or start using a transpiler like Babel
Reference for polyfill
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744767329a4592541.html
评论列表(0条)