一. 对象的展开 扩展运算符与 rest 参数

Rest 参数与 spread 扩展运算符在ES6中已经引入,不过ES6只针对于数组。

在ES9中为对象提供了像数组一样的 rest 参数和 扩展运算符

1. 输出
function connect({host,port,userName,password}){
	console.log(host)
	console.log(port)
	console.log(userName)
	console.log(password)
}

connect({
	host: '127.0.0.1',
	port: '8080',
	userName: 'root',
	password: '1234567'
})

// 127.0.0.1
// 8080
// root
// 1234567
2. 输出
function connect({host,port,...user}){
	console.log(host)
	console.log(port)
	console.log(user)
}

connect({
	host: '127.0.0.1',
	port: '8080',
	userName: 'root',
	password: '1234567'
})
// 127.0.0.1
// 8080
// {userName: "root", password: "1234567"}
3. 输出
const skillOne = {q:'java'}
const skillTwo = {w:'php'}
const skillThree = {e:'vue'}
const skillFour = {r:'javascript'}

const message = {...skillOne, ...skillTwo, ...skillThree, ...skillFour}
console.log(message);      //{q: "java", w: "php", e: "vue", r: "javascript"}
posted @ 2020-11-26 13:52  小蓉儿  阅读(225)  评论(0编辑  收藏  举报