gpt4 book ai didi

javascript - 如何记录对象属性?

转载 作者:行者123 更新时间:2023-12-02 19:58:43 25 4
gpt4 key购买 nike

如何记录具有预期对象属性的对象属性?例如,如果对象是这样的:

var Object = {
/**
*
*/
point: null
}

该点具有以下结构:

{
x,
y
}

有没有说该点应该具有 x 和 y 属性?好吧,我当然可以在描述中做到这一点,但我一直在寻找更好的方法来做到这一点,就像在参数中我们可以这样做:

/**
* @param {Object} point
* @param {Number} point.x
* @param {Number} point.y
*/

最佳答案

您始终可以创建一个 Point 类。

function Point(x, y) {
this.x = x;
this.y = y;
}

然后

var Object = {
/**
* new Point(x, y)
* @param {Point} point a point class
*/
point: null
}

否则我会这样做

/*
* @param {Object} point {x, y}
*/

关于javascript - 如何记录对象属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com