From b6ae6e52f99c0c3c45ad787328a2e800ff07ca2c Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 13 Mar 2012 10:02:56 -0700 Subject: fix(indexOf): use native impl if available --- src/Angular.js | 7 +++---- src/directive/form.js | 6 +----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index cdffcf1d..282dad5f 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -503,13 +503,12 @@ function size(obj, ownPropsOnly) { function includes(array, obj) { - for ( var i = 0; i < array.length; i++) { - if (obj === array[i]) return true; - } - return false; + return indexOf(array, obj) != -1; } function indexOf(array, obj) { + if (array.indexOf) return array.indexOf(obj); + for ( var i = 0; i < array.length; i++) { if (obj === array[i]) return i; } diff --git a/src/directive/form.js b/src/directive/form.js index db645188..8c172889 100644 --- a/src/directive/form.js +++ b/src/directive/form.js @@ -98,11 +98,7 @@ function FormController(name, element) { function addControlError(validationToken, control) { var queue = errors[validationToken]; if (queue) { - for (var i = 0, length = queue.length; i < length; i++) { - if (queue[i] === control) { - return; - } - } + if (indexOf(queue, control)) return; } else { errors[validationToken] = queue = []; -- cgit v1.2.3