const propsDefault = {
open: false,
payload: {
title: '默认提交',
styles: stylesDefault,
data: '默认显示内容',
onSubmit: null,
diableSubmit: false,
onCancel: null,
diableCancel: false,
},
};
function defaultProps(payload) {
const formatedProps = {};
if (payload.onSubmit === undefined) { formatedProps.onSubmit = propsDefault.payload.onSubmit; } else { formatedProps.onSubmit = payload.onSubmit; }
if (payload.diableSubmit === undefined) { formatedProps.diableSubmit = propsDefault.payload.diableSubmit; } else { formatedProps.diableSubmit = payload.diableSubmit; }
if (payload.onCancel === undefined) { formatedProps.onCancel = propsDefault.payload.onCancel; } else { formatedProps.onCancel = payload.onCancel; }
if (payload.diableCancel === undefined) { formatedProps.diableCancel = propsDefault.payload.diableCancel; } else { formatedProps.diableCancel = payload.diableCancel; }
if (payload.title === undefined) { formatedProps.title = propsDefault.payload.title; } else { formatedProps.title = payload.title; }
if (payload.styles === undefined) { formatedProps.styles = propsDefault.payload.styles; } else { formatedProps.styles = payload.styles; }
if (payload.data === undefined) { formatedProps.data = propsDefault.payload.data; } else { formatedProps.data = payload.data; }
return formatedProps;
}
这写法太难看了 ES6 有什么好看的写法?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.