I have a code snippet that I have been using and works. It is used a lot in my application and I need to speed it up. Is there a faster better way of deep accessing objects using a string path. It needs to able to access properties and methods, see my examples below:

         function get(obj, path) {
            var paths = path.split('.'),
            curProp = obj;
            for(var i=0;i<paths.length;i++){
                if (!curProp[paths[i]]) return 
                curProp = (typeof curProp[paths[i]] !== "function") ? curProp[paths[i]] : curProp[paths[i]]() ;
            }
            return curProp;
        }

The snippet gets the property via the path for the object passed

    var obj = {contact:{name:"john"}};
    console.log(get(obj, "contact.name"));

If the object has a method that returns an object it can return that too

    var obj = {contact:function(){return {name:"john"}}};
    console.log(get(obj, "contact.name"));