Explanation
“@instance:” allows us to attach an object/value to the Foo class instead of Foo’s prototype. Recall that “@” in CoffeeScript refers to JavaScript’s “this”.
After “@instance:” there is a function that is immediately executed. This function returns a function, closed around a variable called instance. Both these functions have their context (their “this”) bound to the Foo object using CoffeeScript’s wonderful “define and bind” operator “=>” as opposed to the normal function definition operator “->”.
When called, the function that “@instance” ends up referring to simply checks to see if the “instance” variable is empty and if so, assigns a new instance of Foo to it. Newing up a Foo is done using the “@” symbol since the function’s “this” refers to the Foo object. It then returns the instance.
Output
The CoffeeScript above compiles down to this:
https://azartspelu-liegums.com
Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how to
get listed in Yahoo News? I’ve been trying for
a while but I never seem to get there! Thank youhttps://azartspelu-liegums.com
Hi there, just wanted to tell you, I enjoyed this blog post.
It was helpful. Keep on posting!
What i don’t realize is actually how you’re not actually much more neatly-appreciated than you may be
right now. You’re so intelligent. You understand therefore significantly in the case of this topic, produced me in my view consider it
from so many numerous angles. Its like women and men aren’t fascinated until it
is something to do with Woman gaga! Your own stuffs outstanding.
Always take care of it up!
Hello, I enjoy reading all of your article post. I wanted to write a
little comment to support you.