http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/
fetch('http://localhost:3000/tasks/')
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(ex) {
console.log('parsing failed: ', ex)
});
fetch('http://localhost:3000/tasks/', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"title": "Add a blogpost about Angular2",
"dueDate": "2015-05-23T18:25:43.511Z",
"done": false
})
}).then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(ex) {
console.log('parsing failed: ', ex)
});
Javascript 方法与函数的区别
https://stackoverflow.com/questions/155609/difference-between-a-method-and-a-function
https://stackoverflow.com/questions/15285293/method-vs-functions-and-other-questions
https://john-dugan.com/javascript-functions-vs-methods/
https://stackoverflow.com/questions/16223531/javas-methods-vs-functions