#194 ✓invalid
Douwe M.

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

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

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...)

Comments and changes to this ticket

  • MadRabbit

    MadRabbit February 16th, 2010 @ 05:47 PM

    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.

  • Douwe M.

    Douwe M. February 16th, 2010 @ 05:50 PM

    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.

  • MadRabbit

    MadRabbit February 17th, 2010 @ 12:17 AM

    • State changed from “new” to “invalid”
  • Douwe M.

    Douwe M. February 17th, 2010 @ 12:23 AM

    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.

  • MadRabbit

    MadRabbit February 17th, 2010 @ 12:44 AM

    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

  • Douwe M.

    Douwe M. February 17th, 2010 @ 01:19 AM

    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...

  • MadRabbit

    MadRabbit February 17th, 2010 @ 01:45 AM

    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.

  • Douwe M.

    Douwe M. February 17th, 2010 @ 01:52 AM

    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.

  • MadRabbit

    MadRabbit February 17th, 2010 @ 02:03 AM

    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?

  • Douwe M.

    Douwe M. February 17th, 2010 @ 02:19 AM

    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?

  • MadRabbit

    MadRabbit February 17th, 2010 @ 11:17 AM

    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.

  • 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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

RightJS Core Tickets

Shared Ticket Bins

People watching this ticket

Tags

Pages