javascript - 将属性对象的选定对象从原型(prototype)插入数组

标签 javascript oop

首先我对标题表示歉意。

我有一个尚未实例化的原型(prototype):

noZoomzoom对象将在实例化时填充对象。

我想插入propertiesToIlluminate array noZoom 内的所有对象我的 Persona 中所有属性的对象构造函数。

function Persona() {
    this.headArea = {
        noZoom: {},
        zoom: {}
    }
    this.torsoArea = {
        noZoom: {},
        zoom: {}
    }
    this.arm = {
        noZoom: {},
        zoom: {}
    }
    this.leg = {
        noZoom: {},
        zoom: {}
    }
    this.pelvis = {
        noZoom: {},
        zoom: {}
    }
    this.abdomen = {
        noZoom: {},
        zoom: {}
    }

    this.illuminate = function() {
        var propertiesToIlluminate = [],
            prop, illuminateInternal, i = 0,
            delay = 100,
            intervalId;
        for (prop in //what to put here//) {
            propertiesToIlluminate.push(prop);
        }
    }
}

最佳答案

试试这个:

for (prop in this) {
    if (this[prop].noZoom) {
        for (key in this[prop].noZoom) {
            if (this[prop].noZoom.hasOwnProperty(key)) {
                propertiesToIlluminate.push(this[prop].noZoom[key]);
            }
        }
    }
}

关于javascript - 将属性对象的选定对象从原型(prototype)插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587541/

相关文章:

oop - 您将如何改进这个简单的类以使其更松散耦合?

javascript - Jquery 悬停在 html 中不起作用

java - 如何阻止程序读取每一行并弹出每一行的消息?

javascript - 你能通过 AJAX 将谷歌地图插入到页面中吗

javascript - 为什么 express.js 路由发送的 html 页面没有连接到 css 样式表?

Java 设计,如何避免将对象向下传递到层次结构中?!?不可能的?

python - 对象 A 包含对象 B1 和 B2,B1 包含 C,包含 D。让 D 更改 B2 中某些内容的最佳方式是什么?

perl - 如何以 `can`看不到的方式隐藏基类中的方法?

javascript - $http 请求来自 Angular 拦截器吗?

javascript - 如何在弹出窗口中显示日历