Can static private variables in JavaScript be written in constructors instead of in private scopes?

(function(){
    var privateVar = 10;
    function privateFun = function(){
        return false;
    }
    MyObject = function(){    
    };
    MyObject.prototype.publicMethod = function(){
        privateVarPP;
        return privateFun();
    }
})();
Can I write

in this way?

function MyObject(){
    var privateVar = 10;
    function privateFun = function(){
        return false;
    }
    MyObject.prototype.publicMethod = function(){
        privateVarPP;
        return privateFun();
    }
}

I mean, there seems to be no difference between the two writing methods, both for code reuse and for private variables to be shared by instances.

Jan.27,2022
Menu