JS - 构造函数引用 [英] JS - Constructor referencing

查看:145
本文介绍了JS - 构造函数引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:如何获得构造函数/属性的内容,而实际上不知道它包含什么?

TLDR: How can you get the contents of a constructor/properties without actually knowing what it contains?

/ p>

Given the following:

    function f(args) {
        this.defaults {
            param1 : 100,
            param2 : 900;
        };
        this.ranges {
            param1 : { min : 0, max : 500 },
            param2 : { min : 0, max : 1000 };
        };
    }
    var myF = new f();

defaults 范围可以通过 myF.defaults.param1 myF.ranges.param1.min 调用。如果您不知道默认值范围的名称怎么办?如何在不知道 defaults 属性的情况下获取名称和值?

The defaults and ranges can be accessed through the myF.defaults.param1 and myF.ranges.param1.min calls. What if you do not know the name of the defaults or the ranges? How can you get the names and values within the defaults property without knowing them?

示例:功能;一个如显示,F#2与 param37 / param42 和F#3与 param68 / param94 。如何调用F#2并返回或找到它包含 param37 / param42 及其值?

Example: Three of the above function; one like shown, F#2 with param37/param42 and F#3 with param68/param94. How can you call F#2 and return or find out it contains param37/param42 and their values?

注意:明确定义范围而不定义 defaults 没有意义,是坏的编码,这就是为什么我倾向于获得默认,而不是两个。

NOTE: Obviously defining ranges without defining defaults would make no sense and be bad coding, which is why I angled the question towards getting the defaults and not both.

推荐答案

如何枚举javascript对象的属性?

这里的答案解决了,这是我自己的错误重复。谢谢。

The answers in here solved it and this was a duplicate by my own error. Thanks.

这篇关于JS - 构造函数引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆