js单例模式

GiantGorp = {};
GiantGorp.DataParser = (function() {
	var reg = /\s+/gi;
	function tirm(str) {
		return str.replace(reg, "");
	}
	function split(str, delimiter) {
		return str.split(delimiter);
	}
	return {
		toArray : function(str, delimiter, isTirm) {
			if (!str)
				return;
			if (isTirm)
				str = tirm(str);
			return split(str, delimiter);
		}
	}
})();

GiantGorp.singleton = (function() {
	var uniqueInstance;
	function constructor() {
		var reg = /\s+/gi;
		function tirm(str) {
			return str.replace(reg, "");
		}
		function split(str, delimiter) {
			return str.split(delimiter);
		}
		return {
			toArray : function(str, delimiter, isTirm) {
				if (!str)
					return;
				if (isTirm)
					str = tirm(str);
				return split(str, delimiter);
			}
		}
	}
	return {
		getInstance : function() {
			if (!uniqueInstance) {
				uniqueInstance = constructor();
			}
			return uniqueInstance;
		}
	}

})();

你可能感兴趣的:(单例模式)