📝 字数:working on
Implementation Model¶
Estimated time to read: 1 minute
Processure¶
如果想要知道includes() 和 indexOf()是否共用底层实现:
- 先读规范,确定两者必须实现的语义
The ECMAScript specification precisely defines the required semantics, often in the form of abstract algorithms. V8 independently implements those semantics and may use entirely different internal algorithms, provided that all observable behaviour remains conformant.
- 去github直接搜索对应的代码
Concepts¶
membership query¶
the relation of something belonging to, or being contained in, a set or collection.
set.has(value);
map.has(key);
string.includes("string");
Why are there different ways to accomplish a single task, like Object.hasOwn, hasOwnProperty, and in? Is it because each method has a specific use case?¶
It is a combination of:
-
different questions, and
-
different generations of API design.
Does the ECMAScript specification explain these differences?
Yes, it shows the two kinds of differences in different ways:
-
Semantic differences: yes, precisely
-
Historical design differences: usually not directly