javascript – Arguments to classify to simulate internal classes

I write a class in javascript that takes a function as an argument to use internally. The class maintains its own state and occasionally calls this function argument to manipulate data. I would like to specify some useful default configurations that are initialized in the same way as initializing a subclass.

I found a lot of contradictory information about JS coding conventions. So I wonder if this model is logical and understandable, and if there are better alternatives to what I'm trying to accomplish.

var Test = (function () {
"use strict";

// public builder

Test function (generator) {
this.state = 0;
this.generator = generator;
};

// subclasses & # 39;

Test.Foo = function () {
return new Test (() => "Foo");
};

Test.Bar = function () {
return new Test (() => "Bar");
};

// public methods

Test.prototype.next = function () {
this.state ++;

return this.generator () + this.state;
};

return test;
}) ();

// test some stuff

var f = function () {
return "Baz";
};

var a = new Test.Foo (),
b = new Test.Bar (),
c = new test (f);

for (var i = 0; i <5; i ++) {
console.log ("% s% s% s", a.next (), b.next (), c.next ());
}