[memo/Js] private vs. public fr_code

/**
 * @author mulriver
 */
var PrivateArr = function() {
    
    var arr = [];    // private member variable.
    
    this.add = function(d) { arr.push(d); };
    this.pop = function() { arr.pop(); };
    this.message = function() { alert(arr); };
};

var t1 = new PrivateArr();
t1.add(1);
t1.add(2);
t1.add(3);
//t1.arr.pop();    // it's not allowable.
t1.pop();    // well done.
t1.message();    // => '1,2'

var t2 = new PrivateArr();
t2.add(4);
t2.add(5);
t2.message();    // => '4,5'

var PublicArr = function() {
    this.arr = [];    // it's public.
    
    this.add = function(d) { this.arr.push(d); };
    this.pop = function() { this.arr.pop(); };
    this.message = function() { alert(this.arr); };
};

var t3 = new PublicArr();
t3.add(6);
t3.add(7);
t3.arr.push(8);    // it's possible.
t3.arr.push(9);
t3.message();    // => '6,7,8,9'
t3.arr[1] = 0;
t3.message();    // => '6,0,8,9'