Assign __proto__ to an interface to turn it into an object - clever or dangerous?

后端 未结 1 1700
独厮守ぢ
独厮守ぢ 2021-01-24 00:13

When using postMessage() to copy data to/from a web worker, you can post an object that\'s a class. But on the far side, the received object is just the data (ie an interface, n

相关标签:
1条回答
  • 2021-01-24 00:28

    Some browsers may not support patching __proto__ or, in the future, may stop supporting it.

    I discovered this the hard way when my code stopped working when used in WinRT HTML applications.

    The properper way (in ES5) would be to call Object.create(Constructor.prototype, obj) (see her for more examples)

    0 讨论(0)
提交回复
热议问题