({})是啥
js吧
全部回复
仅看楼主
level 2
西内内内 楼主
学es6的时候碰到了这样一个代码
function connect({host="127.0.0.0",username,password,port}){
console.log(host);
console.log(username);
console.log(password);
console.log(port);
}
connect({
host:'localhost',
username:'root',
password:'root',
port:3306
})
这个connect({})这两个括号是什么意思,没见过,弹幕也没解释的,搜也搜不到,有没有大佬开导开导
2023年02月05日 14点02分 1
level 5
传入的对象 自动展开
connect({host='xxxxx'}){
}
等价于
connect(data){
const host=data.host||'xxxx'
}
2023年02月09日 01点02分 2
level 3
智能函数参数,对象解构的用法。
2023年02月12日 06点02分 3
1