JavaScript从作为函数实参的对象中提取数据
作者:互联网
function userId({id}) { return id; } function whois({displayName: displayName, fullName: {firstName: name}}){ console.log(displayName + " is " + name); } var user = { id: 42, displayName: "jdoe", fullName: { firstName: "John", lastName: "Doe" } }; console.log("userId: " + userId(user)); // "userId: 42" whois(user); // "jdoe is John"
这段代码从user对象中提取并输出id、displayName 和 firstName。
标签:jdoe,displayName,firstName,JavaScript,userId,user,提取,实参,id 来源: https://blog.51cto.com/u_15166492/2711759