src/js/misc.js
function getPropertyValue(obj, path, useGetter) {
    // if (arguments.length < 3) {
    //     useGetter = false;
    // }

    path = path.trim();
    if (path === undefined || path.length === 0) {
        throw new Error("Invalid field path: '" + path + "'");
    }

    // if (obj === undefined || obj === null) {
    //     throw new Error("Undefined target object");
    // }

    var paths = null,
        m     = null,
        p     = null;

    if (path.indexOf('.') > 0) {
        paths = path.split('.');

        for(var i = 0; i < paths.length; i++) {
            p = paths[i];

            if (obj !== undefined && obj !== null &&
                ((useGetter === true && (m = getPropertyGetter(obj, p))) || obj.hasOwnProperty(p)))
            {
                if (useGetter === true && m !== null) {
                    obj = m.call(obj);
                } else {
                    obj = obj[p];
                }
            } else {
                return undefined;
            }
        }
    } else if (path === '*') {
        var res = {};
        for (var k in obj) {
            if (k[0] !== '$' && obj.hasOwnProperty(k)) {
                res[k] = getPropertyValue(obj, k, useGetter === true);
            }
        }
        return res;
    } else {
        if (useGetter === true) {
            m = getPropertyGetter(obj, path);
            if (m !== null) {
                return m.call(obj);
            }
        }

        if (obj.hasOwnProperty(path) === true) {
            obj = obj[path];
        } else {
            return undefined;
        }
    }

    // detect object value factory
    if (obj !== null && obj !== undefined && obj.$new !== undefined) {
        return obj.$new();
    } else {
        return obj;
    }
}
function getPropertyValue(obj, path, useGetter) {
    // if (arguments.length < 3) {
    //     useGetter = false;
    // }

    path = path.trim();
    if (path === undefined || path.length === 0) {
        throw new Error("Invalid field path: '" + path + "'");
    }

    // if (obj === undefined || obj === null) {
    //     throw new Error("Undefined target object");
    // }

    var paths = null,
        m     = null,
        p     = null;

    if (path.indexOf('.') > 0) {
        paths = path.split('.');

        for(var i = 0; i < paths.length; i++) {
            p = paths[i];

            if (obj !== undefined && obj !== null &&
                ((useGetter === true && (m = getPropertyGetter(obj, p))) || obj.hasOwnProperty(p)))
            {
                if (useGetter === true && m !== null) {
                    obj = m.call(obj);
                } else {
                    obj = obj[p];
                }
            } else {
                return undefined;
            }
        }
    } else if (path === '*') {
        var res = {};
        for (var k in obj) {
            if (k[0] !== '$' && obj.hasOwnProperty(k)) {
                res[k] = getPropertyValue(obj, k, useGetter === true);
            }
        }
        return res;
    } else {
        if (useGetter === true) {
            m = getPropertyGetter(obj, path);
            if (m !== null) {
                return m.call(obj);
            }
        }

        if (obj.hasOwnProperty(path) === true) {
            obj = obj[path];
        } else {
            return undefined;
        }
    }

    // detect object value factory
    if (obj !== null && obj !== undefined && obj.$new !== undefined) {
        return obj.$new();
    } else {
        return obj;
    }
}
function getPropertyValue ( obj , path , useGetter ) { // if (arguments.length < 3) { //     useGetter = false; // } path = path . trim ( ) ; if ( path === undefined || path . length === 0 ) { throw new Error ( "Invalid field path: '" + path + "'" ) ; } // if (obj === undefined || obj === null) { //     throw new Error("Undefined target object"); // } var paths = null , m = null , p = null ; if ( path . indexOf ( '.' ) > 0 ) { paths = path . split ( '.' ) ; for ( var i = 0 ; i < paths . length ; i ++ ) { p = paths [ i ] ; if ( obj !== undefined && obj !== null && ( ( useGetter === true && ( m = getPropertyGetter ( obj , p ) ) ) || obj . hasOwnProperty ( p ) ) ) { if ( useGetter === true && m !== null ) { obj = m . call ( obj ) ; } else { obj = obj [ p ] ; } } else { return undefined ; } } } else if ( path === '*' ) { var res = { } ; for ( var k in obj ) { if ( k [ 0 ] !== '$' && obj . hasOwnProperty ( k ) ) { res [ k ] = getPropertyValue ( obj , k , useGetter === true ) ; } } return res ; } else { if ( useGetter === true ) { m = getPropertyGetter ( obj , path ) ; if ( m !== null ) { return m . call ( obj ) ; } } if ( obj . hasOwnProperty ( path ) === true ) { obj = obj [ path ] ; } else { return undefined ; } } // detect object value factory if ( obj !== null && obj !== undefined && obj . $new !== undefined ) { return obj . $new ( ) ; } else { return obj ; } }
Get property value for the given object and the specified property path
@param  {Object} obj  a target object.
as the target object
@param  {String} path property path. Use "`*" as path to collect all available public
properties.
@param  {Boolean} [useGetter] says too try getter method when it exists.
By default the parameter is false
@return {Object} a property value, return undefined if property cannot
be found
@method  getPropertyValue
@for  zebkit
Get property value for the given object and the specified property path