Hi NGan, Your post finally pushed me over the edge into finishing a blog post I've had in "editing" status for a while: http://blog.niftysnippets.org/2009/09/private-methods-in-javascript.html
Hope that's useful, -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 10, 6:10 pm, Ngan <nganp...@gmail.com> wrote: > Hi, I apologize if this question has been asked before. I've tried > googling for this, but did find a good answer. > > What's the best way to have private methods using prototype's > Class.create? > > I've tried... > > var Worker = Class.create((function() { > function initialize() { > this.someVar = "var"; > privateMethod(); > } > > function publicMethod() { > privateMethod(); > } > > function privateMethod() { > console.info(this.someVar); > console.info(this) > } > > return { > initialize: initialize, > publicMethod: publicMethod > }; > > })()); > > Running this will give me: > aWorker = new Worker(); > # console.info(this.someVar) #=> undefined > # console.info(this.someVar) #=> DOMWindow > > However: > aWorker.publicMethod() #=> WORKS! > > Thank you for your time! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---