diff --git a/src/language/JSUtils.js b/src/language/JSUtils.js index 902828ec574..127c63a2943 100644 --- a/src/language/JSUtils.js +++ b/src/language/JSUtils.js @@ -35,6 +35,7 @@ define(function (require, exports, module) { DocumentManager = require("document/DocumentManager"), ChangedDocumentTracker = require("document/ChangedDocumentTracker"), NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, + CollectionUtils = require("utils/CollectionUtils"), PerfUtils = require("utils/PerfUtils"), StringUtils = require("utils/StringUtils"); @@ -396,17 +397,17 @@ define(function (require, exports, module) { * @return {Array.<{offset:number, functionName:string}>} * Array of objects containing the start offset for each matched function name. */ - function findAllMatchingFunctionsInText(text, functionName) { + function findAllMatchingFunctionsInText(text, searchName) { var allFunctions = _findAllFunctionsInText(text); var result = []; var lines = text.split("\n"); - $.each(allFunctions, function (index, functions) { - if (index === functionName || functionName === "*") { + CollectionUtils.forEach(allFunctions, function (functionName, functions) { + if (functionName === searchName || searchName === "*") { functions.forEach(function (funcEntry) { var endOffset = _getFunctionEndOffset(text, funcEntry.offsetStart); result.push({ - name: index, + name: functionName, lineStart: StringUtils.offsetToLineNum(lines, funcEntry.offsetStart), lineEnd: StringUtils.offsetToLineNum(lines, endOffset) }); diff --git a/src/utils/CollectionUtils.js b/src/utils/CollectionUtils.js index e26bda47808..8eff43e703e 100644 --- a/src/utils/CollectionUtils.js +++ b/src/utils/CollectionUtils.js @@ -46,7 +46,23 @@ define(function (require, exports, module) { return -1; } + /** + * Iterates over all the properties in an object or elements in an array. Differs from + * $.each in that it iterates over array-like objects like regular objects. + * @param {*} object The object or array to iterate over. + * @param {function(index, value)} callback The function that will be executed on every object. + */ + function forEach(object, callback) { + var keys = Object.keys(object), + len = keys.length, + i; + + for (i = 0; i < len; i++) { + callback(keys[i], object[keys[i]]); + } + } // Define public API exports.indexOf = indexOf; + exports.forEach = forEach; });