let thesentence = 'I having a good day'
console.log(thesentence.substr(0,4))
substr
有删除线效果,但使用 substring
没问题。
let thesentence = 'I having a good day'
console.log(thesentence.substr(0,4))
substr
有删除线效果,但使用 substring
没问题。
它被划掉是因为它已经过时了。这是一个JS/TS VS Code的特性,被弃用的内容会以删除线的效果显示出来。
如果你将鼠标悬停在上面并等待悬停信息出现,你会看到这个:
@deprecated — 一个为了浏览器兼容性而存在的旧特性
在类型定义的文档注释中(由lib.es5.d.ts定义,是TypeScript的一部分),@deprecated
注解告诉VS Code它已经被弃用了。你可以在这个提交中找到将其标记为弃用的TypeScript类型定义的更改:Update lib types to mark Annex B as deprecated (#43710)。
要了解为什么substr
被弃用,请参阅Why is String.prototype.substr() deprecated?。
.substring()
的方法代替。 - Nick Parsons@deprecated - 用于浏览器兼容性的遗留功能
。 - pilchard