显然,何时弃用和何时删除由开发人员决定,但我想知道如何警告开发人员JavaScript函数已被弃用?
一些流行的语言(Java、C#、Python)以某种形式支持语言级别的弃用。
对于JavaScript,我找不到任何标准方式让开发人员在代码中指示一个函数已被弃用。我所能做的最好的办法就是遵循(大量的)发行说明。
例如,在完整的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.');
- Florian Margaine