0

如果我在 hello.world.planet 中并且我引用 this.two,那将获得兄弟姐妹,我如何在不引用变量名称的情况下引用 hello.planet,类似于“this”

var hello = {
    world: {
        one: {
        },
        two: {
        },
        three: {
        }
    },
    planet: {
    }
}
4

1 回答 1

0

我没有完全按照您想要参考的位置进行操作,但您可以尝试使用 .bind()。我希望这是你所追求的:

var hello = {
    world: {
        one: {
        },
        two: function() {
            alert(this.planet);
        }.bind(hello),
        three: {
        }
    },
    planet: {
    }
}
于 2013-10-02T07:54:22.587 回答