Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

times(), upto() and downto() on Functions

#194

Allow us to use times(), upto() and downto() on functions like this:

var alerter = function(i) {
  alert(i);
};


alerter.times(4);

Instead of having to do this:

var alerter = function(i) {
  alert(i);
};

4..times(alerter);

(I don't know what it is, but the Lighthouse flavored Markdown really seems to dislike me...)

Reported by Douwe M. · February 16th, 2010 @ 01:13 PM

State: invalid
Milestone: none
Assigned to: nobody

Activity

  1. MadRabbit
    MadRabbit

    don't put trailing spaces in your code, and keep the brackets {} like I've changed, then it should be fine.

    As for the feature, I don't really see the advantage. More of that, the original syntax is more readable and natural to me.

    February 16th, 2010 @ 05:47 PM

  2. Douwe M.
    Douwe M.

    Ok, thanks.

    It's more readable when you read it like English, yeah, but it doesn't feel right to me to run a method on a number, to do something with a function... A Number doesn't have anything to do with a function per se.

    February 16th, 2010 @ 05:50 PM

  3. MadRabbit
    MadRabbit
    • State changed from new to invalid

    February 17th, 2010 @ 12:17 AM

  4. Douwe M.
    Douwe M.

    Just like that? :P

    I still really vote for this one... I think Function#times(num) makes much more sense than Number#times(func). Maybe not from a reading-from-left-to-right point of view, but definitely from the Method-does-something-on-Object point of view... IMO it's the same as Function#delay, although the reading-from-left-to-right doesn't count for that one.

    February 17th, 2010 @ 12:23 AM

  5. MadRabbit
    MadRabbit

    I understand that you like the idea, but this is an obvious duplication without any real advantages. And no one likes duplications without advantages :)

    And then, it's kinda non-standard "surprise" method. At least to me.

    So I'm keeping this ticket on hold until there are more people who need it badly

    February 17th, 2010 @ 12:44 AM

  6. Douwe M.
    Douwe M.

    I don't need it badly, it's just an improvement that, at least to me, would make much more sense than the current way of doing this ;-)
    My 'plan' isn't duplicating the feature to work this way too, but replacing the current method that makes no sense to me at all, by something that does make sense, from a 'method does something with the Object, possibly with parameters that tell something about how exactly it should do something' point of view :p
    When I see a Number object in any language, I don't think: 'Maybe there is a method to fire a function /this/ number of times!', but when I see a Function object, I think: 'It would be cool if there was a way to fire this function x times...'. Firing a function x times is an action on the Function, with the number as a parameter that defines how many times to perform this action, not the other way around. You don't do something with the number that you need a function for, it's the other way around...

    February 17th, 2010 @ 01:19 AM

  7. MadRabbit
    MadRabbit

    Okay I see. the Number#times is a standard feature of Ruby, it follows the general Ruby line of metaprogramming magic and readability over classical programming point of view with normal object -> method relations. If you don't have experience with ruby and rails, that might look a bit weird.

    I just love those things in Ruby, and as I mainly targeting Ruby developers I implemented it the same way. The feature is really nice and natural, you just need to get used to it.

    February 17th, 2010 @ 01:45 AM

  8. Douwe M.
    Douwe M.

    Ah okay, that might be it, as I have no experience whatsoever with Ruby... I guess my brain has become so adjusted to the classical programming point of view as you call it, that structures that read just like English (things that should be natural) just aren't compatible anymore. Or something. Well, just keep the Number#times then, I probably won't ever use it, but I'll respect it.

    February 17th, 2010 @ 01:52 AM

  9. MadRabbit
    MadRabbit

    no problem at all, I know several good programmers who don't like the ruby's readability thing and find normal object -> method expressions more clear. And I understand that, Ruby sometimes gets too kinky.

    And as I port many fancy stuff from Ruby, some times it might look a bit strange. But that's all to make Ruby folks feel like home with RightJS.

    btw: which language do you normally work with?

    February 17th, 2010 @ 02:03 AM

  10. Douwe M.
    Douwe M.

    My programming language of choice would be PHP, I know it like the back of my hand. :)
    I remember a tweet by you matching programming languages to JS libraries... What did you match PHP to again?

    February 17th, 2010 @ 02:19 AM

  11. MadRabbit
    MadRabbit

    that was jQuery. but I simply mocking jQuery users, I myself spent about 5 years working with php, then switched for Rails when it emerged.

    February 17th, 2010 @ 11:17 AM

  12. Douwe M.

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.