gpt4 book ai didi

javascript - 它继承自的字符串的原型(prototype)是什么?

转载 作者:行者123 更新时间:2023-12-02 16:32:09 24 4
gpt4 key购买 nike

我环顾四周,发现 JavaScript 并没有真正的字符串比较方法来测试相等性。我已经看到接受的方法是使用 === 运算符。作为一个首先学习过 Java 或 C++ 等经典语言的人,这让我感到害怕,因为对我来说,它的行为方式实际上并不是我想要的。

因此,我决定编写自己的方法来比较字符串是否相等,但这让我想知道要增强什么原型(prototype),以便所有字符串都可以访问此方法。这引出了我的问题;字符串继承自什么原型(prototype)?

最佳答案

我不明白你想如何改进平等比较,但是......

it's left me wondering what prototype to augment so that all strings have access to this method.

那就是String.prototype .

All String instances inherit from String.prototype. Changes to the String prototype object are propagated to all String instances.

关于javascript - 它继承自的字符串的原型(prototype)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28204806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com