Skip to content Skip to sidebar Skip to footer

Jsdoc For Special Singleton Pattern

I have a special JS singleton prototype function. Pattern looks more or less like example below. Work fine and do the job, but sadly PhpStorm is totally blind regarding to auto-com

Solution 1:

You can try the following:

/**
 * A description here
 * @class
 * @name Item
 */
var Item = (function(){
    var singletonCollection = {};

    var ItemPrototype = function(id){
        /**
         * method description
         * @name Item#getId
         */
        this.getId = function() {
            return id;
        };

        return this;
    };

    var Constructor = function(id){
        if (! (id in singletonCollection)) {
            singletonCollection[id] = new ItemPrototype(id);
        }

        return singletonCollection[id];
    };

    return Constructor;
})();

Post a Comment for "Jsdoc For Special Singleton Pattern"