>我有一个包含选项卡式面板的组件。该面板中有一个图表。在图表的一个功能中,我做了一个console.log(this)
,能够查看所有内容。 但是,我的主要目的是使用值 this.ownerCt
,这表示它存在,但是当我尝试使用它或控制台时.log它,它报告为未定义。 如果我做一个this.id
或this.idname
我会得到实际的ID。
问题:如果this.SOMETHING
this
中有值,为什么会返回undefined
?
一些代码花絮:这是console.log(this)
.
Ext.Class.newClass
additionalCls: Array[2]
body: Ext.Element.Ext.core.Element
childEls: Array[1]
collapseDirection: "top"
componentCls: "x-panel"
componentLayout: Ext.Class.newClass
componentLayoutCounter: 3
container: Ext.Element.Ext.core.Element
dockedItems: Ext.Class.newClass
el: Ext.Element.Ext.core.Element
id: "stackedbarportlet-1055"
itemId: "graph"
items: Ext.Class.newClass
ownerCt: Ext.Class.newClass
xtype: "stackedbarportlet"
我拿出了几个实例,但这是它的一般输出!
console.log(this.ownerCt)
结果为:undefined
。
<script>
var t1="";
var t2;
if (t1===undefined)
{
alert("t1 is undefined");
}
if (t2===undefined)
{
alert("t2 is undefined");
}
</script>
如果运行该 t2 未定义可能这个.ownerCt没有价值
你可以在这里找到你的答案。似乎有时console.log()
调用会排队并最终在当前语句结束后调用,因此它们的输出不一定像在代码中那样准确反映当下的对象状态。
至少,当我重写自定义 ExtJS 存储中的构造函数时,我遇到了类似的行为。