coffee scrip layzy function implementation

Posted by bbz on Stack Overflow See other posts from Stack Overflow or by bbz
Published on 2011-03-08T12:54:37Z Indexed on 2011/03/08 16:10 UTC
Read the original article Hit count: 210

I would like to something like this in JavaScript

var init = function () {
              // do some stuff once
              var once = true

              // overwrite the function 
              init = function () {
                 console.log(once)
              }

}

CoffeeScript adds another local var init to the initial init so the second init doesn't overwrite the first one

var init = function () {
              var init //automatically declared by coffeescript
              // do some stuff once
              var once = true

              // overwrite the function 
              init = function () {
                 console.log(once)
              }

}

Some tips for solutions / workarounds would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about coffeescript

Related posts about lazy-initialization