-
Notifications
You must be signed in to change notification settings - Fork 2k
super compiles differently depending on how class method is defined #3232
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
Comments
Please please please can we kill |
At least disable it in static methods :(. |
This seems like a compiler bug, in that I would expect the latter form to fail the same way as the following: -> super
[stdin]:1:4: error: cannot call super outside of an instance method.
-> super
^^^^^
|
I think it makes sense that you can write
and calling |
For the record, a similar bug appears when using normal functions inside the class body: class X
fun = ->
super var X;
X = (function() {
var fun;
function X() {}
fun = function() {
return X.__super__.fun.apply(this, arguments);
};
return X;
})(); And referencing
|
Wow, until today I thought the only way to create static methods was this way:
Then I found this #279 with
How did we get into this state where both are possible? That will be I guess impossible to remove from the language, in which case the behavior should match. |
@xixixao: Yes, |
|
@xixixao CoffeeScript doesn't add class-based OOP, it just offers syntactic sugar that makes JavaScript's standard prototypal inheritance look like classes—and, regrettably, adds that I don't see the problem with writing |
@erisdiscord I didn't say that CoffeeScript adds class-based OOP and every language in the end is just a syntactic sugar over
I assume Jeremy didn't change his mind over the last three months, so object = {data: 4}
method = (n) -> this.data + n
alert method.call object, 3 Makes it more explicit what's being called. |
@xixixao alright, mr. smartypants. I think you know what I meant. CoffeeScript expands on JavaScript's semantics, but it doesn't somehow automagically change the native prototypal inheritance into classical inheritance. And that's a cute example, but it's not really analogous, now, is it? Besides, there are actually valid cases where you'd write code (kind of) like that. 😒 Calling a known ancestor's implementation of a method you've consciously shadowed with your own implementation ain't quite the same situation as calling methods on arbitrary objects, though. |
@erisdiscord And again, I never said it did. It is quite analogous. a = new A
a.method() What function am I calling here? Method declared in class A, or its super class, or somewhere else where someone overwrote A.prototype.method? The point is, what all this "sugar" gives you is an easier, idiomatic way of expressing programs, in certain paradigm, in this case classical OOP. And back to the topic, if we have |
Baloney, my friend. Pure baloney ;) Prototypes and classes are both ways of accomplishing inheritance with objects. If you have inheritance, then you have |
That was sarcasm.
I totally agree. |
Glad to hear it ;) Ah, GitHub tickets, where nuance is lost, body language is invisible, and smirks go unseen... |
In case it helps the discussion, this block of code illustrates the various possible combinations of variable assignment (@,=,:) and
In
I haven't traced this earlier, but I'm guessing that |
looks like the same issue, revisiting 'Support |
This is caused by the somewhat clunky node construction in the grammar and the unavoidable order of validity checks (The search for illegal Compare:
A dedicated |
Please lets not disable |
#627 |
I just learned another interesting thing :
this results in a |
The
So it looks it is sensitive to the same In the development version the approach to binding for the 'fat arrow' has been changed substantially There is no longer a difference between |
@marchaefner I was going to start tackling this, but your "dedicated |
@jashkenas: I already got a quick'n'dirty fix for this issue and #2949. Just need to work on a proper description since this has some side effects. (I think only positive ones.) The |
Looks like In 11/13 - I rewrote
|
(and remove duplicate `context` assigment)
super
compiles differently in these two snippets:and
The way it compiles in the second snippet seems like a bug to me. See http://stackoverflow.com/a/19865440/66226.
The text was updated successfully, but these errors were encountered: