forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveAt.js
More file actions
45 lines (38 loc) · 1.27 KB
/
Copy pathRemoveAt.js
File metadata and controls
45 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var SpliceOne = require('./SpliceOne');
/**
* Removes the item from the given position in the array.
*
* The array is modified in-place.
*
* You can optionally specify a callback to be invoked for the item if it is successfully removed from the array.
*
* @function Phaser.Utils.Array.RemoveAt
* @since 3.4.0
*
* @param {array} array - The array to be modified.
* @param {integer} index - The array index to remove the item from. The index must be in bounds or it will throw an error.
* @param {function} [callback] - A callback to be invoked for the item removed from the array.
* @param {object} [context] - The context in which the callback is invoked.
*
* @return {*} The item that was removed.
*/
var RemoveAt = function (array, index, callback, context)
{
if (context === undefined) { context = array; }
if (index < 0 || index > array.length - 1)
{
throw new Error('Index out of bounds');
}
var item = SpliceOne(array, index);
if (callback)
{
callback.call(context, item);
}
return item;
};
module.exports = RemoveAt;