1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 /** 6 * @fileoverview Some utility functions that don't belong anywhere else in the 7 * code. 8 */ 9 10 var util = (function() { 11 var util = {}; 12 util.object = {}; 13 /** 14 * Calls a function for each element in an object/map/hash. 15 * 16 * @param obj The object to iterate over. 17 * @param f The function to call on every value in the object. F should have 18 * the following arguments: f(value, key, object) where value is the value 19 * of the property, key is the corresponding key, and obj is the object that 20 * was passed in originally. 21 * @param optObj The object use as 'this' within f. 22 */ 23 util.object.forEach = function(obj, f, optObj) { 24 'use strict'; 25 var key; 26 for (key in obj) { 27 if (obj.hasOwnProperty(key)) { 28 f.call(optObj, obj[key], key, obj); 29 } 30 } 31 }; 32 33 return util; 34 }()); 35