From e0ce9ed36d9b8c1858e4f928b61d21d7d4c023b8 Mon Sep 17 00:00:00 2001 From: RoyLING Date: Sun, 5 Jan 2014 15:51:04 +0800 Subject: refactor(filterFilter): simplify code by a ternary op instead of if-else - use only one IIFE and a ternary op in it, instead of invoking separate IIFEs in if-else (this also completely fixed the same issue closed by PR #3597) - also add a spec to verify usage of '$' property in expression object (e.g. `{$: 'a'}`) Closes #5637 --- src/ng/filter/filter.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index 51c2e7bc..e328d61a 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -173,23 +173,12 @@ function filterFilter() { case "object": // jshint +W086 for (var key in expression) { - if (key == '$') { - (function() { - if (!expression[key]) return; - var path = key; - predicates.push(function(value) { - return search(value, expression[path]); - }); - })(); - } else { - (function() { - if (typeof(expression[key]) == 'undefined') { return; } - var path = key; - predicates.push(function(value) { - return search(getter(value,path), expression[path]); - }); - })(); - } + (function(path) { + if (typeof expression[path] == 'undefined') return; + predicates.push(function(value) { + return search(path == '$' ? value : getter(value, path), expression[path]); + }); + })(key); } break; case 'function': -- cgit v1.2.3