diff options
author | Joris Guyonvarch | 2015-03-07 20:28:24 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-07 20:28:24 +0100 |
commit | 8066367ecdf9ddd4f00cbf6c0bfdf9eebd844f0c (patch) | |
tree | aa6fe384a24e8d22cdbc1de0bfcaed239ed97366 | |
parent | 8e086a0cf8e8c3aa31f0b700399bccc4f735cd89 (diff) |
Replacing var by const in javascript
-rw-r--r-- | router.js | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -4,15 +4,15 @@ this.addEventListener('load', router); function router() { - var url = location.hash.slice(2) || 'presentation'; - var contentElement = document.getElementById('content'); - var htmlElement = document.querySelector('html'); + const url = location.hash.slice(2) || 'presentation'; + const contentElement = document.getElementById('content'); + const htmlElement = document.querySelector('html'); addClass(htmlElement, 'waitCursor'); fetchFile('Pages/' + url + '.md', function(contentMd) { removeClass(htmlElement, 'waitCursor'); contentElement.innerHTML = markdown.toHTML(contentMd); }, function() { - var notFoundPage = '<h1>Page non trouvée</h1><a href="#">Retour à l\'accueil</a>'; + const notFoundPage = '<h1>Page non trouvée</h1><a href="#">Retour à l\'accueil</a>'; contentElement.innerHTML = notFoundPage; }); } @@ -26,18 +26,16 @@ } function fetchFile(url, successHandler, errorHandler) { - var xhr = typeof XMLHttpRequest != 'undefined' + const xhr = typeof XMLHttpRequest != 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); xhr.open('get', url, true); xhr.responseType = 'text'; xhr.onreadystatechange = function() { - var status; - var data; if (xhr.readyState == 4) { - status = xhr.status; + const status = xhr.status; if (status === 200 || status === 0) { - data = xhr.responseText; + const data = xhr.responseText; successHandler && successHandler(data); } else { errorHandler && errorHandler(status); |