Open finnhodgkin opened 7 years ago
This is more personal preference thing (I :heart: destructuring).
This:
const { handleHome, handleAuto, handleIndex, handleCss, handleFavicon } = require('./handlers'); const router = (request, response) => { const url = request.url; if (url === '/') { handleHome(response); } else if (url.indexOf('/auto') !== -1) { handleAuto(request, response); } else if (url.indexOf('/index.js') !== -1) { handleIndex(request, response); } else if (url.indexOf('/main.css') !== -1) { handleCSS(request, response); } else if (url.indexOf('/favicon.ico') !== -1) { handleFavicon(request, response); } else { response.writeHead(404, "Content-Type:text/html"); response.end("<h1>Heather fucked up</h1>"); } } module.exports = router;
Is functionally the same as:
const handlers = require('./handlers'); const router = (request, response) => { const url = request.url; if (url === '/') { handlers.handleHome(response); } else if (url.indexOf('/auto') !== -1) { handlers.handleAuto(request, response); } else if (url.indexOf('/index.js') !== -1) { handlers.handleIndex(request, response); } else if (url.indexOf('/main.css') !== -1) { handlers.handleCSS(request, response); } else if (url.indexOf('/favicon.ico') !== -1) { handlers.handleFavicon(request, response); } else { response.writeHead(404, "Content-Type:text/html"); response.end("<h1>Heather fucked up</h1>"); } } module.exports = router;
Why am I assigned? :laughing:
notes taken. this is a very nice approach.
I was thinking about using array to store the route. but your method is even better, less key stroke~
This is more personal preference thing (I :heart: destructuring).
This:
Is functionally the same as: