如何解构一个对象并仍然能够得到未解构的对象?

How to destructure a obj and still be able to get the NOT destruchtured obj?

我有这个功能:

testFn({email: "test@gmail.com", password: "123"})

你现在可以解构它了:

function testFn({email, password}) {
 console.log(email, password)
}

test@gmail.com 123

但是有没有办法得到初始对象呢?

我听说过这种语法,但它不起作用:

function testFn({email, password, ...objectView}) {
 console.log(email, password,objectView)
}

test@gmail.com 123 {email: "test@gmail.com", password: "123"}

您可以使用 arguments 对象。

testFn({email: "test@gmail.com", password: "123"})

function testFn({email, password}) {
 console.log(email, password);
 console.log(arguments[0])
}

您可以在函数中而不是在参数列表中重构参数对象:

function testFn( arg) {
   const {email, password} = arg;
   console.log( email, password, arg);
}

testFn( {email:"foo@example.com", password: 123});