@babel/plugin-transform-proto-to-assign

Detail

This means that the following will work:

  1. var foo = { a: 1 };
  2. var bar = { b: 2 };
  3. bar.__proto__ = foo;
  4. bar.a; // 1
  5. bar.b; // 2

however the following will not:

  1. var foo = { a: 1 };
  2. var bar = { b: 2 };
  3. bar.__proto__ = foo;
  4. bar.a; // 1
  5. foo.a = 2;
  6. 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

  1. bar.__proto__ = foo;

Out

  1. function _defaults(obj, defaults) { ... }
  2. _defaults(bar, foo);

Installation

  1. npm install --save-dev @babel/plugin-transform-proto-to-assign

Usage

  1. {
  2. "plugins": ["@babel/plugin-transform-proto-to-assign"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-transform-proto-to-assign script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["@babel/plugin-transform-proto-to-assign"]
  3. });

References