nl_tokens: @ngdoc function @name ng . $rootScope . Scope#$watchCollection @methodOf ng . $rootScope . Scope @function
pl_tokens: function ( obj , listener ) { var self = this ; var oldValue ; var newValue ; var changeDetected = 0 ; var objGetter = $parse ( obj ) ; var internalArray = [ ] ; var internalObject = { } ; var oldLength = 0 ; function $watchCollectionWatch ( ) { newValue = objGetter ( self ) ; var newLength , key ; if ( ! isObject ( newValue ) ) { if ( oldValue !== newValue ) { oldValue = newValue ; changeDetected ++ ; } } else if ( isArrayLike ( newValue ) ) { if ( oldValue !== internalArray ) { // we are transitioning from something which was not an array into array. oldValue = internalArray ; oldLength = oldValue . length = 0 ; changeDetected ++ ; } newLength = newValue . <mask> ; if ( oldLength !== newLength ) { // if lengths do not match we need to trigger change notification changeDetected ++ ; oldValue . length = oldLength = newLength ; } // copy the items to oldValue and look for changes. for ( var i = 0 ; i < newLength ; i ++ ) { if ( oldValue [ i ] !== newValue [ i ] ) { changeDetected ++ ; oldValue [ i ] = newValue [ i ] ; } } } else { if ( oldValue !== internalObject ) { // we are transitioning from something which was not an object into object. oldValue = internalObject = { } ; oldLength = 0 ; changeDetected ++ ; } // copy the items to oldValue and look for changes. newLength = 0 ; for ( key in newValue ) { if ( newValue . hasOwnProperty ( key ) ) { newLength ++ ; if ( oldValue . hasOwnProperty ( key ) ) { if ( oldValue [ key ] !== newValue [ key ] ) { changeDetected ++ ; oldValue [ key ] = newValue [ key ] ; } } else { oldLength ++ ; oldValue [ key ] = newValue [ key ] ; changeDetected ++ ; } } } if ( oldLength > newLength ) { // we used to have more keys, need to find them and destroy them. changeDetected ++ ; for ( key in oldValue ) { if ( oldValue . hasOwnProperty ( key ) && ! newValue . hasOwnProperty ( key ) ) { oldLength -- ; delete oldValue [ key ] ; } } } } return changeDetected ; } function $watchCollectionAction ( ) { listener ( newValue , oldValue , self ) ; } return this . $watch ( $watchCollectionWatch , $watchCollectionAction ) ; }