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:
Hi there Dear, are you really visiting this website daily, if so afterward you will absolutely obtain good experience.
Incredible quest there. What happened after?
Thanks!
Thanks in favor of sharing such a good idea, post is nice, thats
why i have read it fully
Good article! We will be linking to this great content on our website.
Keep up the great writing.
An outstanding share! I’ve just forwarded this onto
a friend who had been doing a little homework on this.
And he in fact ordered me lunch because I discovered it for him…
lol. So let me reword this…. Thank YOU for the meal!!
But yeah, thanx for spending the time to discuss this issue here
on your web site.
I’m curious to find out what blog platform you are utilizing?
I’m experiencing some small security issues with my latest website and I would like to find something more safe.
Do you have any solutions?