乐趣区

关于前端:从零打造微前端框架实战汽车资讯平台项目一起学习

'use strict';// 启用严格模式
var oap={},obj_type={},core_toString=obj_type.toString,hasOwn = obj_type.hasOwnProperty;;
    var type_arr = "Boolean Number String Function Array Date RegExp Object Error".split(" ");
    for(var i in type_arr){obj_type[ "[object" + type_arr[i] + "]" ] = type_arr[i].toLowerCase();};
 
    // 常用工具  判断办法 对象
    oap={type:function(obj){if ( obj == null) {return String( obj);
            }
            return (typeof obj === "object" || typeof obj === "function")?(obj_type[ core_toString.call(obj) ] || "object") :typeof obj;
        },
        isStr:function(obj){return oap.type(obj)==="string";
        },
        isFn:function(obj){return oap.type(obj)==="function";
        },
        isObj:function(obj){return oap.type(obj) === "object";
        },
        isDate:function(obj){return oap.type(obj) === "date";
        },
        isEmptyObj:function(obj){
            var name;
            for (name in obj) {return false;}
            return true;
        },
        isNum:function(obj){return !isNaN( parseFloat(obj) ) && isFinite(obj);
        },
        isArr:function(obj){return oap.type(obj) === "array";
        },
        trim:function(obj){return obj.replace(/^\\s+|\\s+$/g, "");
        },
        now:function(){return new Date().getTime();},
        log:function(str){if(console && console.log){console.log(str);
            }
        }
    };
var _cookie = {set:function(name, value){var expires = (arguments.length > 2) ? arguments[2] : null,strExpires = "";
            if(expires && oap.isDate(expires)){strExpires =  "; expires=" + expires.toGMTString();
            }else if(expires && oap.isObj(expires)){var nD = oap.now(),
                    nObj = {day:0,hours:0,minutes:0,seconds:0},
                    dArr={
                        secondes:1000,
                        minutes:1000*60,
                        hours:1000*60*60,
                        day:1000*60*60*24
                    },
                    _val;
                nObj = oap.extend(nObj,expires);
                for(var n in expires){_val = nObj[n];
                    if(oap.isNum(_val) && _val>0){nD = nD + _val * dArr[n];
                    }
                }
                if(oap.isNum(nD) && nD>0){nD = new Date(nD);
                    strExpires =  "; expires=" + nD.toGMTString();}
            }else{strExpires = "";}
 
            document.cookie = name + "=" + encodeURIComponent(value) + strExpires + ";path=/" ;
        },
        get:function(name){var value = document.cookie.match(new RegExp("(^|)" + name + "=([^;]*)(;|$)"));
            if (value != null) {return decodeURIComponent(value[2]);
            } else {return null;}
        },
        remove:function(name){var expires = new Date();
            expires.setTime(expires.getTime() - 1000 * 60);
            this.set(name, "", expires);
        }
    };
退出移动版