Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub
Edit

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

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

function _defaults(obj, defaults) { ... }

_defaults(bar, foo);

Installation

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

Usage

With a configuration file (Recommended)

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

Via CLI

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

Via Node API

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

References

  • MDN: Object.prototype.__proto__
  • Detail
  • Example
  • Installation
  • Usage
    • With a configuration file (Recommended)
    • Via CLI
    • Via Node API
  • References
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x