4 ms·
Recently, I encountered Cookies API that befuddled me. For example, to set Cookies: document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00
by tanin 7y ago
Recently, I encountered Cookies API that befuddled me.
For example, to set Cookies:
document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
To erase it:
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
Getting cookie by key involves splitting string and etc.
There must have been some constraint that shaped this API, and I'd love to learn about that constraint.
If I designed an API like this in a tech interview, nobody would hire me.
- winrid 7y agohttps://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/set https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Web... Will probably be incorporated across browsers at some point. document.cookies just isn't a huge pain because every framework provides abstraction around it. So not many people are motivated to clean it up. Also, document.cookie is a runtime environement thing and not nessarily tied to JS.