I am trying to understand how private and protected properties work in javascript.
I have gotten the general idea, and was playing around making test call between properties.
So far, I have found that:
- Public can call protected
- Protected can call private
- Public can t call private
- Private can call Public
- Protected can call Public
So far so good, but when I tried to make a private function call a protected one, I get a undefined error.
test.js:
var Test = require('./test_.js'),
    test = new Test();
test.prot_func();
test_.js:
function publ_func() {
    console.log('Public');
}
function Test() {
    var priv_var = 0;
    this.prot_func = function prot_func() {
        //OK
        console.log('Protected');
        priv_func();
    };
    function priv_func() {
        //OK
        console.log('Private');
        //OK
        //publ_func();
        test_prot();
        //test_prot is not defined?
        //Also tried: this.test_prot();
    }
    this.test_prot = function test_prot() {
        console.log('Protected');
        publ_func();
    };
}
Test.prototype.publ_func = publ_func;
module.exports = Test;
Do I just have a syntax error, or is there no way to call a protected method from a private one?
 
     
    