babel-plugin-transform-proto-to-assign-robust
This plugin allows Babel to transform all proto assignments to a method that will do a shallow copy of all properties with symbol.
Inspired by babel-plugin-transform-proto-to-assign
Why?
When we using es6 class extend syntax in IE<=10 which has not Object.setPrototypeOf
and __proto__
, so We need use babel-plugin-transform-proto-to-assign
to transforming.
bar.__proto__ = foo
var _defaults = function(obj, defaults) {
var keys = Object.getOwnPropertyNames(defaults)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var value = Object.getOwnPropertyDescriptor(defaults, key)
if (value && value.configurable && obj[key] === undefined) {
Object.defineProperty(obj, key, value)
}
}
return obj
}
_defaults(bar, foo)
The above transform are worked by babel-plugin-transform-proto-to-assign
.
However the _default
function DO NOT
assign the Symbol
static value, but babel-plugin-transform-proto-to-assign-robust
do it!
Transform
bar.__proto__ = foo
;(function (obj, defaults) {
var keys = Object.getOwnPropertyNames(defaults)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var value = Object.getOwnPropertyDescriptor(defaults, key)
if (value && value.configurable && obj[key] === undefined) {
Object.defineProperty(obj, key, value)
}
}
return obj
})(bar, foo);