> Imagine the situation, when loop body removes one element from the > array. It's quite common situation, for example when you operate on > select tag and remove options dynamically in loop body, in each loop > pass. Thus the length of option collection has changed, and the > length must be recalculated.
It makes sense, but I was curious how it is possible, given the fact that in Javascript when you access something as an attribute, it doesn't behave as a function. For example, say you were to create your own object with a .length attribute. Could you recalculate that on the fly? No, unless you defined it as a function and then you'd have to call it as a function (this.length() instead of this.length). (Or is it possible by some means I am unaware of?) So, changing the behavior for built-ins opens up a large can of worms for programming errors. When you call array.length, you expect it to just retrieve a value. If it were a function, array.length(), you'd expect it to be more intensive and you would be more likely to store the value locally. It's inconsistent, and troublesome, given the fact that there could be myriad other similar examples. Anyway, I guess it just annoys me that this is possible because it means I probably have a lot of optimizing I could do that wouldn't have been an issue if they'd made the built-ins behave the same as user-defined objects. Regardless, thanks for bringing it to light; I would've never known otherwise. Greg _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs