1.0.4 • Published 10 years ago
babel-plugin-proto-to-assign v1.0.4
babel-plugin-proto-to-assign
The proto-to-assignplugin will transform all __proto__ assignments to a method that will do a shallow copy of
all properties.
This means that the following will work:
var foo = { a: 1 };
var bar = { b: 2 };
bar.__proto__ = foo;
bar.a; // 1
bar.b; // 2however the following will not:
var foo = { a: 1 };
var bar = { b: 2 };
bar.__proto__ = foo;
bar.a; // 1
foo.a = 2;
bar.a; // 1 - should be 2 but remember that nothing is bound and it's a straight copyThis is a case that you have to be aware of if you intend to use this plugin.
Example
In
bar.__proto__ = foo;Out
var _defaults = ...;
_defaults(bar, foo);Installation
$ npm install babel-plugin-proto-to-assignUsage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["proto-to-assign"]
}Via CLI
$ babel --plugins proto-to-assign script.jsVia Node API
require("babel-core").transform("code", {
plugins: ["proto-to-assign"]
});