Advice about OOP in JS

Actually, about long post on the techniques

Paul, could you please explain actual situation with OOP in JS? I mean, now I use…

Class…

var Foo = function()
{
    Bar.call(this); // quasi extension or misc

    var me = this; // for closures and private methods

    // method overriding
    var oldConstruct = this.construct;
    this.construct = function()
    {
        oldConstruct();

        // something new
    }

    var _p = 1; // private property

    this.getP = function() {return _p;} // public method

    var f = function()
    {
        // private method
    }
}

or singleton…

var singleton = new function()
{
    // something
}

What about interfaces, protected methods, constants and so on?.. I don’t know.

1 Like

Sorry, but I stay away from OOP techniques. Those are techniques from other programming languages that are less effective in JavaScript. Among the many many articles I’ve been seeing about this over the last couple of years is:

1 Like

I disagree with that.

Thank’s a lot for the article. But if this the class realisation in JS, I better stay on “function as class”. At least. there I have a private properties.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.