Skip to content
dotnetwise edited this page Mar 28, 2013 · 3 revisions

You can add as many private methods you want in your derived classes by simply declaring them in the creator function (the function you give as a parameter to either .fastClass or .inheritWith

var A = function (val) {
    this.val = val;
}.define({
    method1: function (x, y, z) {
        this.x = x;
        this.y = y;
        this.z = z;
      }
});

var B = A.fastClass(function (base, baseCtor) {
    function privateMethod(z) { 
        this.z = "some private value" + z;
    }

    this.constructor = function (val) { baseCtor.call(this, val) },
    this.method1 = function (y, z) {
        base.method1.call(this, 'x', y, z);
        privateMethod.call(this, z);
    }
});

var b = new B("b");
b.method1("y", "z");
b.z; //"some private value z"
Clone this wiki locally