Debugging for Dummies II: Epic Failures in Action
Chapter 5: Epic Failures in Action
function getCookieValue(cookieName) {
/* DO NOT USE THIS CODE, IT'S HORRIBLE. */
var cookie = document.cookie.match(/; ?*?${cookieName}=[^;]*/);
return cookie && cookie.length === 2 ? decodeURIComponent(cookie[0].substr(cookie[0].indexOf('=') + 1)) : null;
}
A sample cookie parsing function, don't try this at home.
Epic Failures in Action
This chapter is for those who enjoy watching trainwrecks. Here are some examples of what not to do when debugging:
- Use a single equals sign (=) as a delimiter in your cookie parsing function.
- Use a regular expression with a non-capturing group (*) in a JavaScript environment that doesn't support it.
- Try to debug your code while drunk.
For more on these topics, see our next chapter: Advanced Techniques in Epic Failures.