var VElement=function(tagName,props,children){ this.tagName=tagName; this.props=props||{}; this.children=children||{}; this.key=props?props.key:void 666; var count=0; console.log(this); $.each(this.children,function(i,child){ console.log(this); }); this.count=count; } var vdom=VElement('div',{'id':'container'},['最外层']);
1 回答

茅侃侃
TA贡献1842条经验 获得超21个赞
首先你要明白this
是谁调用它它就指向谁。
在循环外面的那个console
的this
因为是window调用了VElement这个函数,所以this
指向window。
在循环里面$.each
对this
做了修改变成了this.children
,所以循环里面的console
的this
是指向this.children
即传进来的['最外层']
添加回答
举报
0/150
提交
取消