Skip to content

Instantly share code, notes, and snippets.

@notalentgeek
Created October 6, 2017 16:49
Show Gist options
  • Select an option

  • Save notalentgeek/93343e519de6f28f6043b75b364036b0 to your computer and use it in GitHub Desktop.

Select an option

Save notalentgeek/93343e519de6f28f6043b75b364036b0 to your computer and use it in GitHub Desktop.

Revisions

  1. notalentgeek created this gist Oct 6, 2017.
    24 changes: 24 additions & 0 deletions anyton.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var anyton = function (ton, parameters, init_count) {
    if (!init_count) {
    init_count = 1; // Singleton.
    }

    var instances = [];

    this.create_instance = function () {
    if (instances.length < init_count) {
    instances.push(new ton(...parameters)); // No pun intended.
    }

    return instances[instances.length - 1];
    };
    };


    var dummy_object = function () {};
    dummy_object = new anyton(dummy_object, []);

    var a = dummy_object.create_instance();
    var b = dummy_object.create_instance();

    console.log(a === b);