js 工具函数

作者: _嘿嘿_ | 来源:发表于2018-08-30 11:51 被阅读0次

    imeWeb.tools = {

    /*
     判断字符串str1时候包含字符串str2
     */
    isContains: function (str1, str2) {
        var result = false;
        str1 = str1.toUpperCase();
        str2 = str2.toUpperCase();
        if(str1.indexOf(str2) >= 0){
            result = true;
        }
        return result;
    },
    //数据类型判断
    checkType: function (data) {
        return Object.prototype.toString.call(data).slice(8, -1);
    }
    

    }
    /* 判断对象是否相等 */
    imeWeb.isObjectValueEqual = function (a, b) {
    if (typeof a == 'object' && typeof b == 'object') {
    var aProps = Object.getOwnPropertyNames(a);
    var bProps = Object.getOwnPropertyNames(b);
    if (aProps.length !== bProps.length) {
    return false;
    } else {
    for (var i = 0; i < aProps.length; i++) {
    var propName = aProps[i];
    if (typeof a[propName] == 'object' && typeof b[propName] == 'object') {
    imeWeb.isObjectValueEqual(a[propName], b[propName]);
    } else {
    if (a[propName] !== b[propName]) {
    return false;
    }
    }
    }
    return true;
    }
    } else {
    return a === b;
    }
    }

    /* 数组去重 */
    imeWeb.distinct = function (array) {
    var r = [];
    for (var i = 0, l = array.length; i < l; i++) {
    for (var j = i + 1; j < l; j++)
    if (imeWeb.isObjectValueEqual(array[i], array[j])) {
    j = ++i;
    }
    r.push(array[i]);
    }
    return r;
    };

    相关文章

      网友评论

        本文标题:js 工具函数

        本文链接:https://www.haomeiwen.com/subject/hnurwftx.html