4 ms·
Why does it even have that pack method, let alone fill the array backwards? You could just do this._store = Array.prototype.slice.call(arguments). Tuple.unpack(
by kevingadd 13y ago
Why does it even have that pack method, let alone fill the array backwards? You could just do this._store = Array.prototype.slice.call(arguments). Tuple.unpack(callback) isn't any better than callback.apply(x, array), so not sure what value it offers there either. The valueOf definition is the sort of thing that makes me cringe because it would undoubtedly lead to hard-to-diagnose bugs in JS applications. Not sure what anyone would use this type for.
Cute demonstration of ways to extend JS, I guess, but please don't use anything like this code.
- Olical 13y agoIt fills the array backwards because that is the most efficient loop possible within JavaScript when the order does not matter. I added a pack method to enforce some weak limiting on the size of the array. This will only allow you to set an amount of values equal to the initial values that were set. I know you can do it with `slice` etc, but the point was to make something a little different to an array or object inspired by the things I have been learning about functional programming. Please, by all means, treat it as a cute demonstration. That's fine. I personally could see myself using something like this in some situations as a base type to extend from for example. Maybe as a generic coordinate storage system as I have shown in the post. It has many flaws and might not fit in with your opinions or views, but saying "don't use anything like this code" seems a bit heavy handed to me. I think it has a time and a place, no matter how minute that time or place may be.
- kevingadd 13y agoAdding an implicit coercion to number to a tuple type that contains multiple elements in a dynamically typed language is just a bad idea. Period.
- Olical 13y agoOkay, that isn't integral though. This could easily be left out if desired. It's not coercing to a number either, it's simply concatenating. This would work with strings too or any other type that supports valueOf. You have valid points though. I just didn't like to think of this as something that could never be used in the real world. Or at least contain little ideas that could be used in the real world. It has at least some relevance.