![](/img/trans.png)
[英]Im having an issue with setting a piece of javascript code as a background
[英]having a problem with this piece of javascript code
假设定义了动作,但如何访问 someFunction 中的第一个和第二个布尔值?
这是一个对象还是某种解构? 因为我遇到了某种解构错误。
function someFunction(actions, { first = true, second= false }) {
if(first == true) {
console.log("something");
}
}
我得到的错误 -
TypeError: Cannot read property 'first ' of undefined
为此,您必须在调用函数时传递第二个参数。
第二个参数将被解构; delayedActions("foo", "bar")
会起作用,但delayedActions("foo", {})
更有意义。
您可以覆盖递归的默认值:
delayedActions("foo", { recursive:false })
对象参数可以包括不在函数签名对象中的其他内容:
delayedActions("foo", { recursive:true, errorExit:true, fooParam:'bar' })
如果没有第二个参数,你会得到一个错误,比如VM48976:1 Uncaught TypeError: Cannot read property 'recursive' of undefined
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.