var GiantCorp = {};
        GiantCorp.DataParser = (function(){

            var uniqueInstance;

            function constructor(){
                var whitespaceRegex = /\s+/;
                function stripWhitespace(str){
                    return str.replace(whitespaceRegex,'');
                }
                function stringSplit(str,delimiter){
                    return str.split(delimiter);
                }
                return {
                    stringToArray:function(str,delimiter,stripWS){
                        if(stripWS){
                            str = stripWhitespace(str);
                        }
                        var outputArray = stringSplit(str,delimiter);
                        return outputArray;
                    }
                }
            }

            return {
                getInstance:function(){
                    if(!uniqueInstance){
                        uniqueInstance = constructor();
                    }
                    return uniqueInstance;
                }
            }
            
        })();
        
        
        console.log( GiantCorp.DataParser.getInstance().stringToArray('hello world',' '));

 

posted on 2018-07-19 17:36  kerryk  阅读(134)  评论(0编辑  收藏  举报