javascript库应该使用已弃用的注释吗? [英] Should javascript libraries use the deprecated annotation?

查看:136
本文介绍了javascript库应该使用已弃用的注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,由开发人员决定何时弃用以及何时删除,但我想知道如何警告开发人员已经弃用了javascript函数?

Obviously it's up to the developers as to when to deprecate and when to remove, but I'm wondering how to warn developers that a javascript function has been deprecated?

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

Some popular languages (Java, C#, Python) support language level deprecation in some form.

对于Javascript,我找不到任何标准方式,开发人员可以指出函数已被弃用(在代码中)。我能做的最好的就是关注(大量)发行说明。

For Javascript though, I cannot find any standard way that developers can indicate a function has been deprecated (in code). The best I can do is follow (a large number of) release notes.

作为一个例子,grepping jQuery 1.8的完整源代码显示了最小的内联注释:

As an example, grepping the full source of jQuery 1.8 shows minimal inline comments:

# 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似乎没有标准方式或提供有关如何处理此问题的建议。

W3C and MDN don't seem to have a standard way or provide suggestions on how to handle this.

我发现的最好的是JSDoc的 @deprecated 代码。

The best I've found is JSDoc's @deprecated tag.

有没有人知道javascript 是否有我忽略的弃用注释?有更好或更常见的方法吗?

Does anyone know if javascript does have a deprecation annotation that I've overlooked? Are there better or more common ways to do this?

推荐答案

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

这就是jQuery Migrate(1.8 - > 1.9升级)帮助人们升级代码的方法。

This is how jQuery Migrate (for the 1.8 -> 1.9 upgrade) helps people upgrading their code.

来自他们的 wiki


允许开发人员在迁移旧的jQuery代码时识别并修复兼容性问题,开发(未压缩)版本的只要调用了任何功能,插件就会生成控制台警告消息。消息仅在控制台上针对每条唯一消息显示一次。

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库应该使用已弃用的注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆