我正在寻找一种获取javascript对象所有参数的方法。仅构造函数中指定的那些,而不是从父类继承的那些。我在网上找到了很多示例和教程,包括该网站,但没有一个仅过滤在类中专门定义的参数。我找不到自己提取它的任何方法。例如,如果我有一个这样定义的类:
class Camera extends Node{
constructor(type="Camera", name="Camera", position=[0,0,0], target=[0,0,0], up=[0, 1, 0]) {
super(type, name);
...
我想确保只得到:“类型”,“名称”,“位置”,“目标”和“向上”。在这一点上,我尝试了多种变体,但最后一种是:
printClassArguments (object) {
for (const key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
const value = object[key];
console.log("found argument "+key)
}
}
}
不幸的是,该输出:
scene.printClassArguments (scene.cameras[0])
found property _type
found property _name
found property _components
found property _id
found property cameraType
found property _target
found property _up
found property _fov
found property _near
found property _far
found property _aspect
found property _projectionMatrix
found property _viewMatrix
found property transform
found property _defaultViewMatrix
found property _defaultTarget
found property _sensitivity
这不是我想要的。我想念什么?
提前谢谢!