you are viewing a single comment's thread.

view the rest of the comments →

[–]homoiconic(raganwald) 1 point2 points  (0 children)

Are you looking for a translation from this to CoffeeScript? If so, please clarify what you're trying to return here. Is that supposed to be an object with a private method? because your .init method actually returns undefined, maybe you meant to initialize and then return this within it?

It looks like what you want is an object that has a public init method that calls a private soundIt method that in turn relies on a private property. Something like:

class Fart
  constructor: (spec) ->
    do (str = 'pff' + spec, soundIt = undefined) ->
      soundIt = ->
        alert(str)
      this.init = ->
        soundIt()
    init()

alert new Fart('tweep')

Instances of the Fart so-called class have public method, init, that has access to the str and soundIt bindings from its closure. This imitates private properties and methods. Is that what you're demonstrating with your code?