Code Monkey home page Code Monkey logo

Comments (3)

techird avatar techird commented on July 28, 2024

JSDoc @typedef 嘛:

/**
 * @typedef {{ name: string; level: number }} Person
 **/

/** @types {Person[]} */
const persons = [{
   { name: "集鹄大叔", level: 9999 },
   { name: "胡子大叔", level: 1 },
}];

from styleguide.

luzhenzhen avatar luzhenzhen commented on July 28, 2024

那作为函数参数的时候该怎么注释呢?比如:

/**
 * 数字数组参数注释
 *
 * @param {Array.<number>} nums 数字数组
 */
function showNums(nums) {
    // ...
}

/**
 * 对象参数注释
 *
 * @param {Object} user 用户
 * @param {string} user.name 用户姓名
 * @param {number} user.age 用户年龄
 */
function showUser(user) {
    // ...
}

/**
 * 对象数组参数注释
 *
 * @param {Array.<Object>} users 用户数组
 * @param {string} users[i].name 用户姓名
 * @param {number} users[i].age 用户年龄
 */
function showUsers(users) {
    // ...
}

上面的第三个函数注释格式肯定不对,应该怎么去写这种注释呢?

from styleguide.

luzhenzhen avatar luzhenzhen commented on July 28, 2024

emm...
查阅了一些资料,答案如下:

/**
 * Assign the project to a list of employees.
 * @param {Object[]} employees - The employees who are responsible for the project.
 * @param {string} employees[].name - The name of an employee.
 * @param {string} employees[].department - The employee's department.
 */
Project.prototype.assign = function(employees) {
    // ...
};

参考资料:
http://usejsdoc.org/tags-param.html

from styleguide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.