function asyncFetch(url, method, token, body, successCallback, errorCallback) {
const headers = { 'Content-Type': 'application/json' };
if (token !== null) headers.token = token;
// const options = { method: method, headers: headers, body: body};
// const options = { 'method': method, 'headers': headers, 'body': body};
const options = {};
options.method = method;
options.headers = headers;
options.body = body;
if (method === 'GET') {
options.method = 'post';
options.params = { _method: 'GET' };
}
request(url, options)
.then(successCallback)
.catch(errorCallback);
}
注释 1 的写法有不标准提示可以理解
注释 2 的写法也不标准,难道我除了改函数参数变量名就没其他方法漂亮的赋值了?
const options = {};
options.method = method;
options.headers = headers;
options.body = body;
这写法也太 JB 难看了吧?
1
hzymyp 2018-03-30 11:21:22 +08:00 via iPhone 1
const options = { method, headers, body };
|
2
DOLLOR 2018-03-30 11:23:52 +08:00 1
都用上 ES6 了,为何不用更简短的写法呢?
const options = { method, headers, body }; |
3
lolizeppelin OP 哦哦哦 感谢楼上两位
|
4
qhxin 2018-03-30 12:41:00 +08:00
|
5
ahonn 2018-03-30 12:46:34 +08:00
话说.. eslint 提示..你搜一下规则不就知道了吗..
|