第一个解构仅创建
Start和
End变量。如果要创建
current为变量,则需要再次声明。
function ({ current: { selectionStart: Start, selectionEnd: End }, current }, AppStateSetter) {// do something with current , Start , and End}
您可以在Babel编译器上对其进行测试:
这段代码:
const object = { current: { selectionStart: "prop 1", selectionEnd: "prop2" }}const { current: { selectionStart: Start, selectionEnd: End } } = object;
被转移到:
var object = { current: { selectionStart: "prop 1", selectionEnd: "prop2" }};var _object$current = object.current, Start = _object$current.selectionStart, End = _object$current.selectionEnd;
如您所见,
current未创建变量。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)