react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / vendor / core / mapObject.js
81158 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule mapObject9*/1011'use strict';1213var hasOwnProperty = Object.prototype.hasOwnProperty;1415/**16* Executes the provided `callback` once for each enumerable own property in the17* object and constructs a new object from the results. The `callback` is18* invoked with three arguments:19*20* - the property value21* - the property name22* - the object being traversed23*24* Properties that are added after the call to `mapObject` will not be visited25* by `callback`. If the values of existing properties are changed, the value26* passed to `callback` will be the value at the time `mapObject` visits them.27* Properties that are deleted before being visited are not visited.28*29* @grep function objectMap()30* @grep function objMap()31*32* @param {?object} object33* @param {function} callback34* @param {*} context35* @return {?object}36*/37function mapObject(object, callback, context) {38if (!object) {39return null;40}41var result = {};42for (var name in object) {43if (hasOwnProperty.call(object, name)) {44result[name] = callback.call(context, object[name], name, object);45}46}47return result;48}4950module.exports = mapObject;515253