d3: what is the self as in d3.select(self.frameElement).styl

d3: what is the self as in d3.select(self.frameElement).style("height", height + "px");

本文关键字:self d3 frameElement styl select as what is the in      更新时间:2023-09-26

我在许多D3示例中看到如下语句。然而,我不知道这是什么意思。特别是,我不知道这个self代表什么。此外,这是否体现了D3的某种魔力/惯例,或者它只是一个临时的东西?非常感谢。

d3.select(self.frameElement).style("height", height + "px");

顺便说一句,这里是我复制上述语句的例子。

self:如果没有重新定义(通常是this的副本),那么它就是始终指向windowwindow对象。所以它们可以互换使用。

window.frameElement:返回嵌入窗口的元素(如

看到Window.frameElement

在这个例子中,我发现了以下注释:

// Hack to make this example display correctly in an iframe on bl.ocks.org