对象设置默认属性
const menuConfig = { title:null, body:'Bar', buttonText:null, cancellable:true }; function createMenu(config){ config.title=config.title || 'Foo'; config.body = config.body || 'Bar'; config.buttonText = config.buttonText || 'Baz'; config.cancellable = config.cancellable !== undefined ? config.cancellable : true; console.log(config); } createMenu(menuConfig);