显然,何时弃用以及何时删除取决于开发人员,但我想知道如何警告开发人员某个 JavaScript 函数已被弃用?
一些流行语言(Java、C#、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/