News for hackers. Stuff that matters.
Re:Preparing Yourself for Modern JavaScript Development by ricardobeat on Saturday July 07, 2012 @12:01AM (#4210686)
why private methods?
Re:Preparing Yourself for Modern JavaScript Development by aymeric on Saturday July 07, 2012 @01:52AM (#4210855)
var Person = function() { var privateMethod = function() {...}; };
Re:Preparing Yourself for Modern JavaScript Development by swah on Saturday July 07, 2012 @08:57AM (#4211514)
Normally I use code like this to avoid polluting the global namespace -- you might as well throw your functions in there and they will be "private":

    (function(){ 

     })();
Re:Preparing Yourself for Modern JavaScript Development by ricardobeat on Saturday July 07, 2012 @04:40PM (#4212651)
why: what's your reasoning for using them?

A more memory-efficient approach:

    var Person = (function(){
  
      function Person(x){
        this.x = x
      }
      
      function myPrivateMethod(x){
        //...
      }

      Person.prototype.something = function(){
        y = myPrivateMethod(this.x)
      }
    
      return Person 
    })()