显然,何时弃用以及何时删除取决于开发人员,但我想知道如何warn开发人员发现 JavaScript 函数已被弃用?
一些流行的语言(Java http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Deprecated.html, C# https://stackoverflow.com/questions/314505/how-to-mark-a-class-as-deprecated, Python http://docs.python.org/2/library/warnings.html) 以某种形式支持语言级别的弃用。
但对于 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 http://code.google.com/p/jsdoc-toolkit/wiki/TagDeprecated tag.
有谁知道JavaScriptdoes有我忽略的弃用注释吗?有更好或更常见的方法来做到这一点吗?