开发者

Best practice for deprecating functionality in a JavaScript library

I'm writing a Rails add-on that includes Javascri开发者_如何学编程pt that has API methods intended for use by application developers, and I'm wondering what I should do when I deprecate part of that functionality as the code evolves.

If this were Ruby code, I would write a message to STDOUT the first time a deprecated method was called. so the developer will notice ASAP. Perhaps, in JavaScript, I should check for the existence of console, and write a message to console.log()?


I believe an answer to this topic will be somewhat opinionated.

Nevertheless I would follow the way outlined by this blogpost:

  1. Add a @deprecated JSDoc flag.
  2. Mention the version that the method was deprecated.
  3. Figure out a timeframe for when this method will be deleted, including which version it will take place. Otherwise, based on my experience, it stays forever
  4. Use comments liberally to explain the implementation for the benefit of other developers or your future self. This is extremely useful if your use-case is writing a library that others use as a dependency for their work.
  5. Add a console warning message that indicates that the function is deprecated.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜