From cefdaf131dd373cf06907e241a88339452c51313 Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Mon, 24 Jun 2013 20:45:31 -0700 Subject: fix($parse): move global getter out of parse.js --- src/Angular.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Angular.js') diff --git a/src/Angular.js b/src/Angular.js index 1a06815c..c5e54c98 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1078,3 +1078,30 @@ function assertArgFn(arg, name, acceptArrayAnnotation) { (arg && typeof arg == 'object' ? arg.constructor.name || 'Object' : typeof arg)); return arg; } + +/** + * Return the value accessible from the object by path. Any undefined traversals are ignored + * @param {Object} obj starting object + * @param {string} path path to traverse + * @param {boolean=true} bindFnToScope + * @returns value as accessible by path + */ +//TODO(misko): this function needs to be removed +function getter(obj, path, bindFnToScope) { + if (!path) return obj; + var keys = path.split('.'); + var key; + var lastInstance = obj; + var len = keys.length; + + for (var i = 0; i < len; i++) { + key = keys[i]; + if (obj) { + obj = (lastInstance = obj)[key]; + } + } + if (!bindFnToScope && isFunction(obj)) { + return bind(lastInstance, obj); + } + return obj; +} -- cgit v1.2.3