mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-26 06:43:43 +00:00
fix($parse): simplify getterFn
This commit is contained in:
parent
18a1e860a3
commit
8b32900d72
1 changed files with 2 additions and 13 deletions
|
|
@ -693,17 +693,7 @@ function getter(obj, path, bindFnToScope) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
var getterFnCache = {},
|
var getterFnCache = {};
|
||||||
JS_KEYWORDS = {};
|
|
||||||
|
|
||||||
forEach(
|
|
||||||
("abstract,boolean,break,byte,case,catch,char,class,const,continue,debugger,default," +
|
|
||||||
"delete,do,double,else,enum,export,extends,false,final,finally,float,for,function,goto," +
|
|
||||||
"if,implements,import,in,instanceof,int,interface,long,native,new,null,package,private," +
|
|
||||||
"protected,public,return,short,static,super,switch,synchronized,this,throw,throws," +
|
|
||||||
"transient,true,try,typeof,var,volatile,void,undefined,while,with").split(/,/),
|
|
||||||
function(key){ JS_KEYWORDS[key] = true;}
|
|
||||||
);
|
|
||||||
|
|
||||||
function getterFn(path) {
|
function getterFn(path) {
|
||||||
var fn = getterFnCache[path];
|
var fn = getterFnCache[path];
|
||||||
|
|
@ -711,10 +701,9 @@ function getterFn(path) {
|
||||||
|
|
||||||
var code = 'var l, fn, p;\n';
|
var code = 'var l, fn, p;\n';
|
||||||
forEach(path.split('.'), function(key) {
|
forEach(path.split('.'), function(key) {
|
||||||
key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key;
|
|
||||||
code += 'if(!s) return s;\n' +
|
code += 'if(!s) return s;\n' +
|
||||||
'l=s;\n' +
|
'l=s;\n' +
|
||||||
's=s' + key + ';\n' +
|
's=s' + '["' + key + '"]' + ';\n' +
|
||||||
'if (s && s.then) {\n' +
|
'if (s && s.then) {\n' +
|
||||||
' if (!("$$v" in s)) {\n' +
|
' if (!("$$v" in s)) {\n' +
|
||||||
' p=s;\n' +
|
' p=s;\n' +
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue