我有以下功能:
filterList(event) {
var updateList = this.state.initialItems;
updateList = updateList.filter(function(item) {
return item.search(event.target.value) !== -1;
});
this.setState({currentItems: updateList });
}
如果我们通过引用传递,updateList 和 this.state.initialItems 不是指向同一件事吗?
如何复制 this.state.initialItems?
最佳答案
If we are passing by reference isn't updateList and this.state.initialItems pointing to the same thing?
没有。您将返回一个全新的数组(根据 MDN ):
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
关于javascript - 当你通过引用传递时,我们会改变状态吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47620651/