1. babel-plugin-transform-proto-to-assign
Babel plugin for turning __proto__ into a shallow property clone
babel-plugin-transform-proto-to-assign
Package: babel-plugin-transform-proto-to-assign
Created by: babel
Last modified: Mon, 13 Jun 2022 04:05:06 GMT
Version: 6.26.0
License: MIT
Downloads: 15,721
Repository: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-proto-to-assign

Install

npm install babel-plugin-transform-proto-to-assign
yarn add babel-plugin-transform-proto-to-assign

babel-plugin-transform-proto-to-assign

This plugin allows Babel to transform all __proto__ assignments to a method that will do a shallow copy of all properties.

Detail

This means that the following will work:

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

however 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 copy

This 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 --save-dev babel-plugin-transform-proto-to-assign

Usage

Via .babelrc (Recommended)

.babelrc

 {
  "plugins": ["transform-proto-to-assign"]
}

Via CLI

 babel --plugins transform-proto-to-assign script.js

Via Node API

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code