我是 JS 新手,需要使用匿名函数,但是当我像命名函数中那样为参数提供默认值时,我收到错误“Uncaught SyntaxError: Unexpected token =”。
以下是代码摘录:
//some properties
initResize: function(isPlayerInitializing=true){
//some execution
},
//some more properties
我想知道如何为 Javascript 中的匿名函数的参数提供默认值。
最佳答案
并非全部 browsers support这种语法所以你需要用老派的方式来做
initResize: function(isPlayerInitializing){
if (isPlayerInitializing===undefined) {
isPlayerInitializing = true;
}
//some execution
},
关于javascript - 如何在 Javascript 匿名函数中提供默认参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36311236/