“Singleton Function JavaScript” Kode Jawaban

Singleton Function JavaScript

var SingletonFactory = (function(){
    function SingletonClass() {
        //do stuff
    }
    var instance;
    return {
        getInstance: function(){
            if (instance == null) {
                instance = new SingletonClass();
                // Hide the constructor so the returned object can't be new'd...
                instance.constructor = null;
            }
            return instance;
        }
   };
})();

Ashamed Antelope

Menerapkan singleton javascript

var SingletonFactory = (function(){
    function SingletonClass() {
        //do stuff
    }
    var instance;
    return {
        getInstance: function(){
            if (instance == null) {
                instance = new SingletonClass();
                // Hide the constructor so the returned object can't be new'd...
                instance.constructor = null;
            }
            return instance;
        }
   };
})();
Hilarious Hamerkop

Jawaban yang mirip dengan “Singleton Function JavaScript”

Pertanyaan yang mirip dengan “Singleton Function JavaScript”

Lebih banyak jawaban terkait untuk “Singleton Function JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya