Question to the venerable public, I need an internal object, and now I do this:

function FooList () { this.id = 0; this.list = {}; } FooList.prototype = { add: function () { var item = new this.foo(this.id++, this); this.list[item.id] = item; return item; }, get: function (id) { return this.list[id]; }, foo: function (id, parent) { this.id = id; this.parent = parent; } }; FooList.prototype.foo.prototype = { set: function (name) { this.name = name; }, get: function () { return this.name; } }; // Test var list = new FooList; var foo = list.add(); foo.set("name"); console.log(foo); 

How it is correct (compatible with different browsers)

  • What is an "internal object"? - Dmitriy Simushev

0