Sha256: 5c2b3859b010cc3a2fd44586b4d1009f5618fcd3e6de9841007f3b223a67498d

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# babel-plugin-proto-to-assign

The `proto-to-assign`plugin will transform all `__proto__` assignments to a method that will do a shallow copy of
all properties.

This means that the following **will** work:

```javascript
var foo = { a: 1 };
var bar = { b: 2 };
bar.__proto__ = foo;
bar.a; // 1
bar.b; // 2
```

however the following **will not**:

```javascript
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 copy
```

This is a case that you have to be aware of if you intend to use this plugin.

## Example

**In**

```javascript
bar.__proto__ = foo;
```

**Out**

```javascript
var _defaults = ...;

_defaults(bar, foo);
```

## Installation

```sh
$ npm install babel-plugin-proto-to-assign
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": ["proto-to-assign"]
}
```

### Via CLI

```sh
$ babel --plugins proto-to-assign script.js
```

### Via Node API

```javascript
require("babel-core").transform("code", {
  plugins: ["proto-to-assign"]
});
```

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
ilog-0.4.1 node_modules/babel-plugin-proto-to-assign/README.md
ilog-0.4.0 node_modules/babel-plugin-proto-to-assign/README.md
ilog-0.3.3 node_modules/babel-plugin-proto-to-assign/README.md
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/babel-plugin-proto-to-assign/README.md
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/babel-plugin-proto-to-assign/README.md
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/babel-plugin-proto-to-assign/README.md
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/babel-plugin-proto-to-assign/README.md
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/babel-plugin-proto-to-assign/README.md