Created
January 17, 2016 13:22
-
-
Save zwacky/9682e4acaaa655288305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* e.g. retrieving field values from a form. | |
*/ | |
function getDateFromForm() { | |
const props = ['year', 'month', 'day', 'hour', 'minutes', 'sec', 'milisec']; | |
return props.map((prop) => { | |
return document.querySelector(`#${prop}`).text; | |
}); | |
} | |
const dateFields = getDateFromForm(); | |
const d = new Date(...dateFields); // et voilà | |
// ---------- | |
// instead of | |
// ---------- | |
var year = document.querySelector('#year').text; | |
var month = document.querySelector('#month').text; | |
var day = document.querySelector('#day').text; | |
var hour = document.querySelector('#hour').text; | |
var min = document.querySelector('#min').text; | |
var sec = document.querySelector('#sec').text; | |
var milisec = document.querySelector('#milisec').text; | |
var d = new Date(year, month, day, hour, min, sec, milisec); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment