我是JS的初学者,我有一个关于最佳实践的问题。我有几个函数调用相同的API,但在数据返回时对数据执行不同的操作。我知道,对于重复的代码,我们应该创建一个新函数,但是仅仅为了获取数据而创建一个新函数是否有意义呢?
我至少要重复4次,就像这样:
showAllBooks(user){
fetch(`url`)
.then(response => response.json())
.then(json => {
//show all books for user
});
});
showShortestBooks(user){
fetch('url')
.then(response => response.json())
.then(json => {
//map through data and show shortest books in user's library
});
});
}发布于 2018-06-19 02:56:46
有两件事:
https://stackoverflow.com/questions/50919931
复制相似问题