常见的JavaScript实现是否使用字符串实习? [英] Do common JavaScript implementations use string interning?

查看:144
本文介绍了常见的JavaScript实现是否使用字符串实习?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常见的JavaScript引擎,例如V8和WebKit的JavaScriptCore,使用字符串实习来获取JavaScript字符串?或者他们实际上在内存中保留了多个相同字符串的实例?

Do common JavaScript engines, such as V8 and WebKit's JavaScriptCore, use string interning for JavaScript strings? Or do they actually keep multiple instances of identical strings in memory?

推荐答案

是的。通常,JS源中的任何文字字符串,标识符或其他常量字符串都是实体。然而,实现细节(确切地说是实例内容)会有所不同,以及发生实习的时间。

Yes. In general any literal string, identifier, or other constant string in JS source is interned. However implementation details (exactly what is interned for instance) varies, as well as when the interning occurs.

请注意,字符串值与String对象不同,字符串对象没有被实习,因为这基本上是不正确的行为。

Note that a string value is not the same as a String Object though, String Objects are not interned because that would be fundamentally incorrect behaviour.

这篇关于常见的JavaScript实现是否使用字符串实习?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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