Why String.prototype.substr() seems to be deprecated?

前端 未结 1 1594
傲寒
傲寒 2020-12-19 05:25

It is mentionned on the ECMAScript standard here that :

... These features are not considered part of the core ECMAScript language. Programmers shou

相关标签:
1条回答
  • 2020-12-19 05:57

    Because it's never been part of the standardized language. It wasn't in the ECMAScript 1 or 2 specs at all, and only appears in ECMAScript 3 in Section B.2 ("Additional Properties") (and subsequent editions in similar annexes), which said:

    Some implementations of ECMAScript have included additional properties for some of the standard native objects. This non-normative annex suggests uniform semantics for such properties without making the properties or their semantics part of this standard.

    Moreover, substr is largely redundant with substring and slice, but the second argument has a different meaning,.

    In pragmatic terms, I'd be surprised if you found a full mainstream JavaScript engine that didn't provide it; but I wouldn't be surprised if JavaScript engines targeted at embedded/constrained environments use didn't provide it.

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