-
Notifications
You must be signed in to change notification settings - Fork 156
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
--> function binder shorthand? #1071
Comments
hmm.. not good. sorry. |
I'm sorry, I don't quite understand what you're proposing... perhaps you figured out that |
well, i thought about this syntax method = (param1, param2) !-->
@property = true to this syntax method = function(this$) {
return function(param1, param2) {
this$.property = true;
};
}; so, it will act like
It looks very implicit.. ye. but if you know how you defined it shouldn't be the problem. shorthand is for both function and first parameter that will become |
method = (param1, param2) !-->
@property = true currently produces a curried function, so that exact syntax is out. However, there's precedent for ‘assigning to method = (this) -> (param1, param2) !~>
@property = true (The It's more verbose than your proposal, but also more explicit and made of more reusable parts. |
oh, i didn't noticed that with parameters it will be curried function... well, i like in case, when there is no parameters in the inner function it will be: method = (this) -> !~>
@property = true which doesn't look great, right? method1 = (this) !~>
@property = true
method2 = (this, param1, param2) !~>
@property = true hmm.. docs are saying that method1 = (this, boundParam1, param2, param3) !~~>
@property = true
method2 = (this, boundParam1, boundParam2, param3) !~~~>
@property = true or better method1 = (this, boundParam1, [param2, param3]) !~>
@property = true
method2 = (this, boundParam1, boundParam2, [param3]) !~>
@property = true but i compromise to your variant, anyway |
Repeating the ‘shaft’ of a function arrow ( On principle, I'm opposed to two things that these last few suggestions would require:
I'll take f = (this, a = @a) -> a should probably compile to var f;
f = function(this$, a){
a == null && (a = this$.a);
return a;
}; and f = (a, {obj: this} = a) -> @foo should compile to var f;
f = function(a, arg$){
var this$;
this$ = (arg$ != null ? arg$ : a).obj;
return this$.foo;
}; but then for consistency, I think f = (a = @a, {obj: this} = a) -> @foo has to compile to var f;
f = function(a, arg$){
var this$;
a == null && (a = this.a);
this$ = (arg$ != null ? arg$ : a).obj;
return this$.foo;
}; so the effect of |
Okay, i understand your first example, but the rest look complicated to me, why not reduce the syntax trigger to only the first i mean something like this: method = (this, param1, [param2, param3]) !~>
@property = true to var method = function(this$, param1) {
return function(param2, param3) {
this$.property = true;
};
}; ..using |
Again, I don't want to create more than one function with a single arrow symbol. So to create that JavaScript code, which contains a function that returns a function, you'd write method = (this, param1) -> (param2, param3) !~>
@property = true Sorry if I confused you with all those other examples; they weren't meant to apply to your use case. What I'm trying to do is show the implications of letting |
Okay, now i got it. |
for example, i have this code:
it compiles to:
later, i iterate a list of those methods and bind them with this code:
i could do:
but with multiple objects,
function.prototype.bind
works slow.what you think about this syntax:
..or, if it does return something, it could be
-->
without!
. i could uselet
syntax, but it creates binder functions each time. how to approach this?The text was updated successfully, but these errors were encountered: