Path: blob/trunk/third_party/closure/goog/dom/pattern/callback/counter.js
2871 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Callback object that counts matches.16*17* @author [email protected] (Robby Walker)18*/1920goog.provide('goog.dom.pattern.callback.Counter');21222324/**25* Callback class for counting matches.26* @constructor27* @final28*/29goog.dom.pattern.callback.Counter = function() {30/**31* The count of objects matched so far.32*33* @type {number}34*/35this.count = 0;3637/**38* The callback function. Suitable as a callback for39* {@link goog.dom.pattern.Matcher}.40* @private {Function}41*/42this.callback_ = null;43};444546/**47* Get a bound callback function that is suitable as a callback for48* {@link goog.dom.pattern.Matcher}.49*50* @return {!Function} A callback function.51*/52goog.dom.pattern.callback.Counter.prototype.getCallback = function() {53if (!this.callback_) {54this.callback_ = goog.bind(function() {55this.count++;56return false;57}, this);58}59return this.callback_;60};616263/**64* Reset the counter.65*/66goog.dom.pattern.callback.Counter.prototype.reset = function() {67this.count = 0;68};697071