Javascript String toObjectReference()

Description

Javascript String toObjectReference()

// Convert string to object reference

String.prototype.toObjectReference = function() {

    var levels,behaviour,depth,i;

    levels = this.split('.');
    depth = levels.length;/*from w ww.ja  va 2  s.  c  o m*/
    behaviour = window;

    for (i=0;i<depth; i++)
    {
        if (behaviour[levels[i]] === undefined) {
            return null;
        }
        behaviour = behaviour[levels[i]];
    }

    return behaviour;
};



PreviousNext

Related