Skip to content

Pass @what to resulting function both as this and first argument #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

johnbergvall
Copy link

Pass @what to resulting function both as this and first argument to allow for @-shortcut in coffeescript

@raganwald
Copy link
Owner

This pull request is quite simple, but there are larger forces in play. As written, .K and .T turn functions into methods. And by function, I mean something that operates on its parameters. Binding this (@ in CoffeeScript) changes the model from binding a function to creating a temporary method definition.

I quite like that idea, but then you move into the question of why @what would be set as this and passed as the first parameter. A true drop-in method definition would bind this and then only pass other parameters as needed. So for example, pop_n would be defined as:

pop_n = (n) -> 
  for x in [1..n]
    @pop()

I really would like to think about how to accommodate this case while still accommodating the more “functional” approach.

@johnbergvall
Copy link
Author

Very valid point.

I'm not very fond of both this and an argument either. Making it a method feels kind of wrong in some instances. My reasoning was that both has cases were they make the code more readable than the other, and this would allow the choice while keeping 100% backward compatibility with the current version.

Great work by the way. I showed it to a colleague today, and he was thrilled.

Reg Braithwaite [email protected] skrev:

This pull request is quite simple, but there are larger forces in play. As written, .K and .T turn functions into methods. And by function, I mean something that operates on its parameters. Binding this (@ in CoffeeScript) changes the model from binding a function to creating a temporary method definition.

I quite like that idea, but then you move into the question of why @what would be set as this and passed as the first parameter. A true drop-in method definition would bind this and then only pass other parameters as needed. So for example, pop_n would be defined as:

pop_n = (n) ->
for x in [1..n]
@pop()

I really would like to think about how to accommodate this case while still accommodating the more “functional” approach.


Reply to this email directly or view it on GitHub:
#11 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants