我正在使用以下代码
function(props){
...
this.props.appName = this.options.appName || this.props.appName;
this.props.host = this.options.host || this.props.hos;
this.props.endpoint = this.options.endpoint || this.props.endpoint;
this.props.appPath = this.options.appPath || this.props.appPath;
....
在使用逻辑运算符or
(||)之前,我使用了类似于下面的代码:
this.props = Object.assign(this.props, props);
我有很多需要赋值的字段,有没有更短的方法?
this.props = {...this.props, ...this.options}
? - gorakObject.assign
的方式? - Oboo Cheng0
、""
和false
的值也将被替换。 - Slai