Adding scope variable to an constructor

Posted by Lupus on Stack Overflow See other posts from Stack Overflow or by Lupus
Published on 2012-09-01T09:27:01Z Indexed on 2012/09/01 9:38 UTC
Read the original article Hit count: 189

Filed under:
|
|

I'm trying to create a class like architecture on javascript but stuck on a point. Here is the code:

var make = function(args) {
    var priv = args.priv,
        cons = args.cons,
        pub = args.pub;
    return function(consParams) {

        var priv = priv,
            cons = args.cons;

        cons.prototype.constructor = cons;
        cons.prototype = $.extend({}, pub);

        if (!$.isFunction(cons)) {

            throw new Hata(100001);

        }
        return new cons(consParams);
    }
};

I'm trying to add the priv variable on the returned function objects's scope and object scope of the cons.prototype but I could not make it;

Here is the usage of the make object:

var myClass = make({
    cons: function() {
        alert(this.acik);
    },
    pub: {
        acik: 'acik'
    },
    priv: {
        gizli: 'gizli'
    }
})
myObj = myClass();

PS: Please forgive my english...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about oop