javascript - JavaScript 库是否应该使用已弃用的注解?

标签 javascript deprecated deprecation-warning

显然,何时弃用以及何时删除取决于开发人员,但我想知道如何警告开发人员某个 JavaScript 函数已被弃用?

一些流行语言(JavaC#Python)以某种形式支持语言级别的弃用。

不过,对于 JavaScript,我找不到任何标准方式让开发人员可以指示某个函数已被弃用(在代码中)。我能做的最好的就是遵循(大量)发行说明。

例如,grep jQuery 1.8 的完整源代码显示了最少的内联注释:

# curl http://code.jquery.com/jquery-1.8.0.js | grep -i depre
// jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode
// *** attrChange attrName relatedNode srcElement  are not normalized, non-W3C, deprecated, will be removed in 1.8 ***
// Some plugins are using, but it's undocumented/deprecated and will be removed.
// Deprecated
// Limit scope pollution from any deprecated API
// Deprecated, use jQuery.browser.webkit instead

W3C 和 MDN 似乎没有标准方法或提供有关如何处理此问题的建议。

我找到的最好的是 JSDoc 的 @deprecated标签。

有谁知道 JavaScript 是否 有一个我忽略的弃用注释?有没有更好或更常见的方法来做到这一点?

最佳答案

console.log('This function is deprecated.');

这就是 jQuery Migrate(针对 1.8 -> 1.9 升级)如何帮助人们升级他们的代码。

来自他们的 wiki :

To allow developers to identify and fix compatibility issues when migrating older jQuery code, the development (uncompressed) version of the plugin generates console warning messages whenever any of its functionality is called. The messages only appear once on the console for each unique message.

关于javascript - JavaScript 库是否应该使用已弃用的注解?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14363740/

相关文章:

c# - 我自己托管的 NuGet 服务器不再正常工作

deprecation-warning - Rails 5.1.1 弃用警告 changed_attributes

javascript - 从 REST API 读取 JSON 响应始终返回空文本

python - 如何忽略 Python 中的弃用警告

javascript - vue2.js 组件 vmodel 传递数据

Symfony 2 产品环境 已弃用的调用

java - 如何弃用内部接口(interface)

javascript - Angular 元素 - Element.createShadowRoot 弃用

javascript - Fetch 给我的是 javascript 而不是 HTML

带有隐藏函数的 JavaScript 扩展类