Possible (minor) enhancement for Math.random()
-
MadRabbit
- Milestone set to 2.0.0 Release
- Tag changed from arguments, math.random, string to math.random, string
- Milestone order changed from 196625 to 0
Hi Imperative, a nice trick you've gout in here! Never herd about it before, thanks for that. Will check it out and then include into RightJS 2.0
-
algorithmic_imperative
MadRabbit - Of the three versions I posted, I guess I'd lean toward the last one. It will offer the most possibilities for string values.
For example, it could accept values line "50px", which may be useful for passing the value of style properties.
// Set height to random value between the current height and 250 element.style.height = Math.random(element.style.height, 250) + "px"; -
MadRabbit
hmm... sounds a bit naughty to me, besides you always can call it like that
element.setHeight(Math.random(element.size().y, 250));which is more explicitly saying what's going on
-
algorithmic_imperative
MadRabbit - Very true, and perhaps a little naughty. :o) The main point was that using
parseInt()would allow for additional valid arguments. Not a big deal, though.One question, if you don't mind me going a little off topic here. I noticed in some of your
Numbermethods, you add0tothis.For example:
min: function(value) { return this < value ? value : this + 0; // 0 is added when returning the Number },Just curious about it.
-
MadRabbit
that's simple type-conversion
typeof(new Number(8)); // -> 'object' typeof(new Number(8) + 0); // -> 'number'If you simply return
thisit will carry all those additional methods like a number which sometimes causes problems. So I simply convert it back to a number. -
algorithmic_imperative
Ah, got it. Thanks.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.