JavaScript 为什么操作 __proto__ 很慢? [英] JavaScript Why manipulating __proto__ is slow?

查看:63
本文介绍了JavaScript 为什么操作 __proto__ 很慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此线程相关:JavaScript 修改函数原型的更好方法,我想知道为什么变异实例的 __proto__ 是一个缓慢的操作.

Relating this thread : JavaScript better way to modify function prototype, I was wondering why mutating instances' __proto__ is a slow manipulation.

我知道它已被弃用,我经常在网上阅读它.但我一直没有找到原因.为什么它真的被弃用了,为什么它很慢?

I know it is deprecated, I often read it on the web. But I have never found why. Why is it really deprecated, and why is it slow ?

setPrototypeOf() 是否会是更好的解决方案,至于性能?

Will setPrototypeOf() be a better solution, as for performance ?

推荐答案

我想知道为什么变异实例的原型是一个缓慢的操作.

在您的浏览器中实现 JavaScript 语言的人做了一个权衡:他们想要支持这个深奥的"功能,但通过降低这种操作的速度来提高语言的其余部分的速度.

The people who implemented the JavaScript language in your browser made a trade-off: They wanted to support this "esoteric" feature, but made the rest of the language faster by making this manipulation slower.

你应该只在编写程序后担心 __proto__ 的速度.对于很多用例来说,额外的缓慢"只会导致整个程序出现几毫秒的差异,没有人会在意.

You should only worry about the speed of __proto__ after you write your program. For many use cases, the extra "slowness" will only result in a few miliseconds difference in the overall program, and nobody will care.

这篇关于JavaScript 为什么操作 __proto__ 很慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆