javascript object's - private methods: which way is better.

Posted by Praveen Prasad on Stack Overflow See other posts from Stack Overflow or by Praveen Prasad
Published on 2011-01-10T08:12:42Z Indexed on 2011/01/10 10:53 UTC
Read the original article Hit count: 228

(function () {
    function User() {
        //some properties
    }

    //private fn 1
    User.prototype._aPrivateFn = function () {
        //private function defined just like a public function, 
        //for convetion underscore character is added
    }

    //private function type 2
    //a closure
    function _anotherPrivateFunction() {
        // do something
    }

    //public function   
    User.prototype.APublicFunction = function () {

        //call private fn1
        this._aPrivateFn();

        //call private fn2
        _anotherPrivateFunction();
    }

    window.UserX = User;
})();

//which of the two ways of defining private methods of a javascript object is better way, specially in sense of memory management and performance.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery