CoffeeScript lazy singleton class instance function

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:

1,317 thoughts on “CoffeeScript lazy singleton class instance function

  1. Greetings! Quick question that’s completely off topic. Do you know how to make your site mobile friendly?
    My web site looks weird when browsing from my apple iphone.
    I’m trying to find a theme or plugin that might be able to fix this issue.

    If you have any suggestions, please share. Many thanks!

  2. you’re really a excellent webmaster. The site loading pace is incredible.
    It kind of feels that you are doing any distinctive trick.
    Also, The contents are masterpiece. you’ve performed a great job on this topic!

  3. Хотите вывести ваш сайт на первые
    позиции поисковых систем Яндекс и
    Google?
    Мы предлагаем качественный линкбилдинг
    — эффективное решение для увеличения
    органического трафика и роста конверсий!

    Почему именно мы?

    - Опытная команда специалистов, работающая исключительно белыми методами SEO-продвижения.

    - Только качественные и тематические доноры ссылок, гарантирующие стабильный рост позиций.

    - Подробный отчет о проделанной работе и прозрачные условия сотрудничества.

    Чем полезен линкбилдинг?

    - Улучшение видимости сайта в поисковых системах.

    - Рост количества целевых посетителей.

    - Увеличение продаж и прибыли вашей компании.

    Заинтересовались? Пишите
    нам в личные сообщения — подробно
    обсудим ваши цели и предложим индивидуальное решение
    для успешного продвижения вашего бизнеса онлайн!

    Цена договорная, начнем сотрудничество прямо сейчас вот на адрес
    ===>>> ЗДЕСЬ Пишите обгаварим все
    ньансы!!!

  4. Menurut saya, artikel ini sangat bagus karena berhasil mengulas KUBET, Situs Judi Bola, Situs
    Judi Bola Terlengkap, Situs Parlay Resmi, Situs Parlay Gacor, dan Situs Mix Parlay sekaligus.

  5. This is a great tip particularly to those fresh to the blogosphere.

    Short but very accurate info… Thanks for sharing this one.
    A must read article!

  6. Amazing! This blog looks exactly like my old one!
    It’s on a completely different subject but it has pretty much the same page
    layout and design. Outstanding choice of colors!

  7. Quality articles is the important to be a focus for the users to go to see the website, that’s what this web site is
    providing.

  8. I simply couldn’t leave your site before suggesting that
    I actually enjoyed the standard info a person supply for your guests?

    Is gonna be again incessantly in order to check out new posts

  9. I know this if off topic but I’m looking into starting my own blog and was wondering what all is required to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% sure. Any suggestions or advice would
    be greatly appreciated. Many thanks

  10. We stumbled over here by a different web address and thought I should
    check things out. I like what I see so i am just following you.
    Look forward to finding out about your web page repeatedly.

  11. I used to be suggested this blog by means of my
    cousin. I’m not sure whether this put up is written by way of him as no one else realize such special approximately my difficulty.

    You are wonderful! Thanks!

  12. Hello There. I discovered your weblog using msn. That is an extremely smartly written article.
    I’ll be sure to bookmark it and return to
    learn extra of your useful info. Thank you for the post.

    I will definitely return.

  13. Undeniably believe that which you stated. Your favorite
    justification seemed to be on the web the easiest thing to be aware of.
    I say to you, I certainly get irked while people think about worries that they plainly don’t know
    about. You managed to hit the nail upon the top as well as defined out
    the whole thing without having side effect , people could take a
    signal. Will probably be back to get more. Thanks

  14. Appreciating the persistence you put into your blog and detailed information you
    offer. It’s awesome to come across a blog every once
    in a while that isn’t the same outdated rehashed material.
    Wonderful read! I’ve saved your site and I’m including your RSS feeds
    to my Google account.

  15. What’s up to all, since I am actually eager of reading this web site’s post to be
    updated on a regular basis. It consists of good material.

  16. This design is wicked! You obviously know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my own blog (well,
    almost…HaHa!) Fantastic job. I really loved what you had to say, and more than that, how
    you presented it. Too cool!

  17. Hey exceptional website! Does running a blog similar to this require a massive amount
    work? I have absolutely no understanding of coding however
    I had been hoping to start my own blog soon. Anyhow, should you have any ideas or tips for new blog owners please share.
    I understand this is off topic however I simply needed to
    ask. Thanks!

  18. Good day! Would you mind if I share your blog with my
    myspace group? There’s a lot of folks that I think would
    really enjoy your content. Please let me know. Thank
    you

  19. Excellent goods from you, man. I have take into accout your stuff prior to and you’re just extremely wonderful.

    I really like what you have bought here, certainly like what you’re stating and the best way wherein you
    say it. You are making it enjoyable and you continue
    to take care of to keep it sensible. I can not wait to read far more from you.
    This is really a terrific website.

  20. Oh my goodness! Amazing article dude! Thank you so much, However
    I am going through troubles with your RSS. I don’t know the reason why
    I cannot join it. Is there anybody else having the same RSS problems?
    Anyone that knows the solution will you kindly respond?
    Thanks!!

  21. I was suggested this web site by my cousin. I’m not sure whether this post is
    written by him as no one else know such detailed about my trouble.
    You are amazing! Thanks!

  22. tear trough filler in Newdigate, Surrey Hey guys, someone checked out It’s Me n You Clinic Kingston upon Thames instead of Thames Skin Clinic as well as Love Teeth Dental?

    I’ve looked up loads of reviews, and they’ve got good ratings, but I’d rather hear from someone first-hand.

    A colleague mentioned them, but I’m weighing up my options.

    Would you recommend them? Much appreciated.

    my blog post … sloggi pull on bra; https://abetterlifecbd.com/,

  23. What’s up to all, the contents present at this web site are in fact awesome for people
    knowledge, well, keep up the nice work fellows.

  24. Greetings I am so glad I found your weblog, I really found you by error,
    while I was searching on Google for something else, Nonetheless I am here now and would just
    like to say thanks a lot for a tremendous post and a all round thrilling blog
    (I also love the theme/design), I don?t have time to browse it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be
    back to read more, Please do keep up the fantastic work.

    Also visit my website … Burton

  25. Hi there, I do believe your web site might be having browser compatibility issues.
    When I take a look at your site in Safari, it looks fine however, when opening in I.E., it’s
    got some overlapping issues. I just wanted to provide you with a quick heads up!
    Aside from that, great site!

  26. Today, I went to the beach front with my kids. I found a sea
    shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put
    the shell to her ear and screamed. There was a hermit crab inside and
    it pinched her ear. She never wants to go back! LoL I know this
    is totally off topic but I had to tell someone!

  27. I think this is among the most significant information for me.
    And i’m glad reading your article. But want to remark
    on some general things, The web site style is
    ideal, the articles is really great : D. Good job, cheers

  28. You may even tickle and graze the shaft together with your fingers/fingernails.” Then, as soon as your partner’s penis is absolutely erect and stuffed with blood, you can begin sucking with extra pressure.

  29. Saya merasa artikel ini begitu informatif karena mengulas Situs Parlay
    Resmi dengan cara yang sederhana tetapi tetap menyeluruh.

    Banyak orang yang masih bingung membedakan situs
    terpercaya dengan yang abal-abal, dan penjelasan ini benar-benar membuat
    perbedaan.
    Ditambah lagi kaitannya dengan Situs Judi Bola membuat isi artikel lebih relevan.

  30. Hmm is anyone else experiencing problems with the pictures
    on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

  31. My family members all the time say that I am killing my time here at net,
    however I know I am getting know-how every day by reading such
    fastidious content.

  32. I’m gone to inform my little brother, that he should also pay a visit
    this blog on regular basis to get updated from most recent news update.

  33. Link exchange is nothing else but it is only placing the other person’s web site link on your page at suitable place and other person will also do similar
    in favor of you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>