Last active
July 4, 2018 09:19
-
-
Save FQ400/6d16b527ea3af1d7aea54583c4af1a63 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Access the global variable document | |
*/ | |
const browserUrlParser1 = (url) => { | |
const p = document.createElement('a'); | |
p.href = url; | |
return p; | |
} | |
/* | |
A default parameter that can be overwritten in tests | |
*/ | |
const browserUrlParser2 = (url, doc=document) => { | |
const p = doc.createElement('a'); | |
p.href = url; | |
return p; | |
} | |
/* | |
A function that returns a function | |
*/ | |
const createBrowserUrlParser = (doc) => (url) => { | |
const p = doc.createElement('a'); | |
p.href = url; | |
return p; | |
} | |
const browserUrlParser3 = createBrowserUrlParser(document); | |
/* | |
Using object destructuring and default values | |
*/ | |
const browserUrlParser4 = ({url, doc=document}) => { | |
const p = doc.createElement('a'); | |
p.href = url; | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment