-
Notifications
You must be signed in to change notification settings - Fork 2k
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
className property on class objects #494
Comments
Why not just attach the |
I recall Harmony is adding a |
Wouldn't that be lovely. I'm afraid that
|
Hmm, right now there's no string representation of the class name anywhere in CoffeeScript, right? That does seem like an omission. But the proposed approach doesn't sound very intuitive. It would mean:
Now, maybe it's for the best that I can define
This fails because I'll try to make my critique more coherent in a separate issue. This is interesting stuff. :) |
On further reflection, I think that the right approach is to override
then I'd much rather get 'Dog' than the entire definition of the Dog constructor. I guess it's possible, in principle, that someone would want the function definition string at runtime so that they could modify it and run it through |
[Github apparently ate my first attempt at making this comment. Gotta copy+paste before submitting in the future.] On further reflection, I think that the right approach is to override
to return 'Dog', rather than the entire |
Make this behaviour optional using a command line switch |
I wouldn't want to have to set a compiler flag in order to use rich, reflective classes... those should be a narrative part of the language. If you don't want to use those features, you don't have to use the Also, Google Closure Compiler would probably remove any features you don't use during minification anyway. It's quite smart about detecting "dead code." |
+1 I do the following - if there was a non fruity way of it happening automatically I would like that. class Zing < ManualRecord |
In the end, I think that if we did this, we should really do it through named function expressions. ie:
Has this constructor in JS:
But, because of the IE memory and scoping problems with named functions, documented in extensive detail here by kangax: http://yura.thinkweb2.com/named-function-expressions/ I don't think that we want to go there, and risk subtle incompatibilities with certain uses of nested classes in Internet Explorer. Adding an extra special property to every class feels a bit silly -- why not add it to every single function? So, I think you have two good alternatives ... if you're simply checking for class identity, use Closing the ticket as a |
For those looking at this issue and wondering why it is labeled
|
I would like to reopen the discussion of this. @jashkenas is on the money about class Shopify.Shop extends Batman.Model
__name__: 'Shop' or, having to override the specific options everywhere we use them, which looks equivalently silly. class Shopify.Order extends Batman.Model
@url: 'orders' It's certainly possible to do this for every class so our handy string manipulators can provide these defaults, but it is a real bummer. This problem exists for anyone using |
@hornairs +100. I'm doing the same thing. className is probably a bad name though because that is used by DOM elements already. And to get the className on instances as well all you have to do is this: class Dog
constructor: ->
@className = @constructor.className I think it's actually quite intuitive. |
Coco uses |
Harry, Devon -- give |
It's a Christmas miracle. Thanks a bunch Jeremy! |
It's been suggested that we add a
.className
property on all classes for easier debugging. Basically:Do you think it would be too presumptuous of us to reserve it as a special property, or are you in favor of the idea?
The text was updated successfully, but these errors were encountered: