Should javascript libraries use the deprecated annotation?

☆樱花仙子☆ 提交于 2019-12-31 21:42:47

问题


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?

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

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.

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 and MDN don't seem to have a standard way or provide suggestions on how to handle this.

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

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


回答1:


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

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

From their 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.




回答2:


Basically there's not the way to deprecate a method/function. It's up to the developer handle the deprecated members.

The only things I guess are possible to do is to do the best effort in documenting that deprecated functions/methods, and use the @deprecated tag inside the source code documentation.

Then, some compiler (Google Closure Compiler does it, if I'm not wrong) and advanced IDE, could use this tag to verify the compiled source code and fires warnings if some deprecated function is used.



来源:https://stackoverflow.com/questions/14363740/should-javascript-libraries-use-the-deprecated-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!