5 ms·
Nice list. One of the things that CoffeeScript manages to do, with greater or lesser success, is to avoid many of these "bad parts": * Global variables can no
by jashkenas 15y ago
Nice list. One of the things that CoffeeScript manages to do, with greater or lesser success, is to avoid many of these "bad parts":
* Global variables can no longer be created by accident ... you must explicitly `window.global = ...` them.
* Semicolons are gone, along with the headaches of automatic semicolon insertion.
* I'm afraid that not much can be done about `typeof` without a more invasive replacement, unfortunately.
* The + operator continues to work the same way.
* CoffeeScript does not have `==` or `!=`, only `===` and `!==` for strict equality comparisons. In the one location where `==` can be helpful, checking for either null or undefined, you may use the existential operator.
* When dealing with too many falsy values, there's an existential operator, which allows you to ask the question: Does this value exist? (Is this value not null or undefined?)
name = ""
if name?
# Exists, so this will run.
* There's a shortcut to only list the "own properties" when iterating over the keys and values of an arbitrary objects, without including members from the prototype chain:
for own key, value of object
alert key + ": " + value
- boucher 15y agoAmusingly (to me at least) the only thing Objective-J really addresses from that list is 'typeof', which we have a much better replacement for :).
- jashkenas 15y agoNice! Got a link to the implementation, or more info? The only reference I found to it is this thread: http://groups.google.com/group/objectivej/browse_thread/thread/f7489e3d71ee95f http://groups.google.com/group/objectivej/browse_thread/thre...
- boucher 15y agoYou're not going to like it :) Rather than use typeof, CPObject has a runtime feature for asking about its class (https://github.com/280north/cappuccino/blob/master/Foundation/CPObject.j#L179 https://github.com/280north/cappuccino/blob/master/Foundatio...). Because we also do "toll-free bridging", you can ask if strings are CPStrings, numbers are CPNumbers, and arrays are CPArrays (though we don't toll free bridge null to CPNull, which we probably should).
- jashkenas 15y agohttps://github.com/280north/cappuccino/blob/master/Foundation/CPObject.j#L164-173 https://github.com/280north/cappuccino/blob/master/Foundatio... Nice. Pure class-object-reference equality up to the root. Won't work calling functions across windows, but who cares.
- boucher 15y agoSo, we actually have this feature where we "bridge" windows: you can basically tell a CPWindow to map to an actual browser window. And we implement it as a display only thing, so all of your actual code runs in the parent browser window and just manipulates the DOM elements in the child window. It doesn't completely work in IE I think, but I haven't tried in a while (it's kind of an experimental feature, but it's been in the release for a while).