On 17.02.2011 1:44, Jason Persampieri wrote:
On Wed, Feb 16, 2011 at 10:02 AM, Dmitry A. Soshnikov
<[email protected] <mailto:[email protected]>> wrote:
By the way, CoffeeScript provides a convenient sugar for that:
obj.foo?.bar? and stuff?()
which desugars into (notice, how elegantly the last "stuff" is
checked to be a functon):
On Wed, Feb 16, 2011 at 1:40 PM, Angus Croll <[email protected]
<mailto:[email protected]>> wrote:
What worries me is the unwanted side effects.
console.log(d.foo.bar.bam) and maybe you just created 3 new objects
The CoffeeScript syntax is very nice, but I'm still not seeing the
necessity of the extra syntax. Don't get me wrong, I'm fairly certain
there's something I'm missing (and I keep thinking it may have to do
with function references... but can't come up with an example).
It to omit initial example, but instead to take a some common abstract,
the last case with a function is useful for me. E.g.
function foo(callback) {
/* stuff */
callback && callback(data);
}
or even:
function foo(callback) {
/* stuff */
typeof callback == "function" && callback(data);
}
In Coffee:
foo = (callback) ->
# stuff
callback?(data)
The "sugar" -- that what does matter in this case. You want to write
this long lines -- it's completely OK, nobody can prevent you from doing
it. You don't want -- it's also OK, use sugar. Also, Coffee's sugar
changes some JS semantics.
You may find additional example on the "The Existential Operator" on
Coffee's page.
Dmitry.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]