Closed
Description
I've found out that React.Children.map/forEach
has an optional argument as [, object thisArg]
which could set this
to another object through Top-Level API, then I try to run the code below:
var obj = {
num : 3
};
var Component = React.createClass({
deal : function(){
console.log(this, this.num); //it`s NOT obj
},
render : function() {
React.Children.forEach(this.props.children, this.deal, obj);
return (<ul>
{this.props.children}
</ul>)
}
});
React.render(
(
<Component>
<li>0</li>
<li>1</li>
<li>2</li>
</Component>
), document.body
)
it logs three times of Constructor undefined
and I have no idea why they are not obj 3
.
so how does the third argument of React.Children.forEach
work?
Metadata
Metadata
Assignees
Labels
No labels