HTML and CSS Reference
In-Depth Information
Limitations
Numbers in JavaScript have limits. For the methods discussed here that involve an
intermediate state of converting to a number, the limit appears to be 1023 yes/no values,
because parseInt('1111…1111',2) returns Infinity when the number of aces is bigger
than 1023. This limit does not apply to the last method, because we're only converting blocks
of bits instead of the whole thing. And, of course, it doesn't apply to the first two methods
(array and string) because they don't involve packing the values into an integer.
“I Think You Took It A Bit Too Far”
This might be overkill for some cases. But it will definitely come in handy when you want to
store a lot of boolean values in any limited space that can only store strings. And no
optimization is overkill for things that go through the wire frequently. For example, cookies are
sent on every single request, so they should be as tiny as possible. Another use case would
be online multiplayer games, for which response times should be lightning-fast, otherwise the
games wouldn't be fun.
And even if this kind of optimization isn't your thing, I hope you've found the thought process
and the code involved educational. ❧
1. http://twitter.com/#!/codepo8
2. http://icant.co.uk/talks/koc2011/
3. http://jsperf.com/json-vs-split-join-for-simple-arrays
4. http://es5.github.com/#x4.3.16
5. http://en.wikipedia.org/wiki/Bit_field
6. http://en.wikipedia.org/wiki/Base_36
7. http://stackoverflow.com/questions/7033639/javascript-split-large-string-in-n-size-chunks
 
 
 
 
 
 
 
Search WWH ::




Custom Search