Prototype only but with encapsulation

by Douglas Enas

JavaScript

var TestObj = (function() { //declaring the constructor  
    'use strict';
    var TestObj = function() {
        this.someProperty = 'whatever';
    }
    // declaring instance methods  
    TestObj.prototype = {
        someMethod: function() {
            alert('someMethod called ' + this.someProperty);
            this.someMethod2();
        },
        someMethod2: function() {
            alert('somemethod2 called from somemethod 1 ' + this.someProperty);
        }
    };
    return TestObj;
})();

function CallMeLater(obj)
{
  setTimeout(obj.someMethod(), 10);  
}


var T1 = new TestObj();

T1.someMethod();

CallMeLater(T1);