[关闭]
@bornkiller 2016-06-09T17:05:43.000000Z 字数 2607 阅读 3081

jsdoc学习笔记

javascript


工程管理

  1. /**
  2. * @author - bornkiller <hjj491229492@hotmail.com>
  3. * @version - 1.0.0
  4. * @licence - private
  5. */

时效管理

JSDOC类型系统

内置类型

显式类型

部分时候,无法从结构中判定类型,比如interfacevirtual comment,或者未立即赋值的变量声明,就需要使用显式的方式来指明。

  1. /**
  2. * @type {(string|Array.)}
  3. * @function
  4. */
  5. var foo;

定义类型

处理非原生类型时,可以采用自定义类型的方式来处理。注意,声明的class即是声明变量,同时声明类型。

声明普通类型。

  1. /**
  2. * @typedef {object} AuthorityModel
  3. *
  4. * @property {string} account
  5. * @property {string} password
  6. *
  7. * @description - 远程登录信息结构
  8. */

在彻底promise化之后,回调函数甚少用到。

  1. /**
  2. * @callback authorityCallback
  3. *
  4. * @param {number} responseCode
  5. * @param {string} responseMessage
  6. *
  7. * @description - This callback is displayed as a global member.
  8. */

事件在部分项目中还是较多使用。

  1. /**
  2. * @event HeroUpdate
  3. * @type {object}
  4. *
  5. * @property {string} name
  6. * @property {number} age
  7. *
  8. * @description - Children event
  9. */

使用自定义事件注释的方式有触发与处理。

  1. /**
  2. * Fire HeroUpdate sync.
  3. *
  4. * @fires HeroUpdate
  5. */
  6. Hurl.prototype.snowball = function() {
  7. this.emit('HeroUpdate', {name: 'kevin', age: 25});
  8. };

从道理上来说,可以配合callback同时使用。

  1. /**
  2. * Catch HeroUpdate sync.
  3. *
  4. * @listens HeroUpdate
  5. */
  6. function handleHeroUpdate(hero) {
  7. console.log(hero);
  8. }

面向对象

可访问性

主要包含五类,private, protect, public, static, abstract。前三类粗放式抽象为@access

  1. /**
  2. * @description - validate email format
  3. *
  4. * @instance
  5. * @function
  6. * @name Validator#isValidEmail
  7. *
  8. * @param {string} email
  9. * @return {boolean}
  10. */
  11. /**
  12. * @description - validate phone format
  13. *
  14. * @inner
  15. * @function
  16. * @name Validator~isValidPhone
  17. *
  18. * @param {string} phone
  19. * @return {boolean}
  20. */
  21. /**
  22. * @description - Generic dairy product.
  23. * @constructor
  24. */
  25. function DairyProduct() {}
  26. /**
  27. * Check whether the dairy product is solid at room temperature.
  28. * @abstract
  29. * @return {boolean}
  30. */
  31. DairyProduct.prototype.isSolid = function() {
  32. throw new Error('must be implemented by subclass!');
  33. };

继承

接口实现。

  1. /**
  2. * Class representing a color with transparency information.
  3. *
  4. * @class
  5. * @implements {Color}
  6. */
  7. function TransparentColor() {}
  8. // inherits the documentation from `Color#rgb`
  9. TransparentColor.prototype.rgb = function() {};
  10. /**
  11. * @description - Get the color as an array of red, green, blue, and alpha values.
  12. *
  13. * @return {Array<number>} An array containing the red, green, blue, and alpha
  14. * values, in that order.
  15. */
  16. TransparentColor.prototype.rgba = function() {};

方法复写。

  1. /**
  2. * @description Abstract class representing a network connection.
  3. * @class
  4. */
  5. function Connection() {}
  6. /**
  7. * @description - Open the connection.
  8. */
  9. Connection.prototype.open = function() {};
  10. /**
  11. * @description Class representing a socket connection.
  12. * @class
  13. * @extend Connection
  14. */
  15. function Socket() {}
  16. /**
  17. * @description - Open the socket.
  18. * @override
  19. */
  20. Socket.prototype.open = function() {};

模块化

错误处理

内联型

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注