Hirdetés

Keresés

Új hozzászólás Aktív témák

  • Jim-Y

    veterán

    válasz martonx #5452 üzenetére

    Felig meddig igazad van, a typeof az onmagaban broken es tipus vizsgalatra nem javallott. Egy dologra alkalmas, undefined vizsgalatra :) Bar en arra is inkabb explicitebb megoldast valasztanek pl
    valami === void 0 de ez egyeni preferencia.

    Kb jQuery + underscore + lodash-bol osszeollozva

    function isString(obj) {
    return $.type(obj) === 'string';
    }

    function isNumber(obj) {
    return exist(obj) && $.isNumeric(obj);
    }

    function isBoolean(obj) {
    return obj === true || obj === false || $.type(obj) === 'boolean';
    }

    function isArray(obj) {
    return exist(obj) && $.isArray(obj);
    }

    function isFunction(obj) {
    return $.type(obj) === 'function';
    }

    function isDate(obj) {
    return $.type(obj) === 'date';
    }

    function isRegExp(obj) {
    return $.type(obj) === 'regexp';
    }

    function isError(obj) {
    return toString.call(obj) === '[object Error]';
    }

    function isUndefined(obj) {
    return obj === void 0;
    }

    function isNull(obj) {
    return obj === null;
    }

    function isEmpty(obj) {

    if (!exist(obj)) {
    return true;
    }

    if (isNumber(obj) || isBoolean(obj) ) {
    return false;
    }

    if (isArray(obj) || isString(obj) || toString.call(obj) === '[object Arguments]') {
    return obj.length === 0;
    }

    return $.isEmptyObject(obj);
    }

    function exist(obj) {
    return !isNull(obj) && !isUndefined(obj);
    }

Új hozzászólás Aktív témák