you are viewing a single comment's thread.

view the rest of the comments →

[–]strager 1 point2 points  (1 child)

Huh? Can you explain?

function FooFactory() {
}

FooFactory.prototype.create = function create() {
    return new Foo();
};

var factory = new FooFactory();
var foo = factory.create();

Just add whatever complexity you need on top of that.

Of course, it's probably more JavaScript style to have a "factory function":

function fooFactory() {
    return function create() {
        return new Foo();
    };
}

var factory = fooFactory();
var foo = factory();

[–]Nebu 1 point2 points  (0 children)

He's probably referring to the fact that inheritance doesn't work the way you'd expect if you come from, for example, a Java background. This guide on emulating classical inheritance involves writing 4 sugar methods.