我试图将一个对象分解为另一个对象,我的意思是从对象 A 到对象 B 的属性子集。我这样做是这样的:
const User = new UserImpl();
User.email = user.email;
User.name = user.name;
User.family_name = user.familyName;
User.password = 'Test!';
User.verify_email = true;
User.email_verified = false;
User.blocked = false;
const {
email,
name,
family_name,
password,
verify_email,
email_verified,
blocked,
connection
} = User;
const res_user = {
email,
name,
family_name,
password,
verify_email,
email_verified,
blocked,
connection
};
return res_user;
但是,有没有办法使用 Object.assign() 来做到这一点?或使用箭头 => 函数而不是有两个变量或分两步执行?
谢谢