Change splice.call(arguments, ..) to use slice

- Bypasses issue of usage incorrectly omitting 2nd argument to `splice`

- More clear of intent; `slice` does not modifify `arguments`

- `slice` is faster across all desktop browsers, by varying degrees
  - Probably due to parameter-aliasing and de-opts when modified.
  - Both `slice` and `splice` create a new Array object
This commit is contained in:
Paul 2015-08-26 23:50:16 -07:00
parent bae732ca9e
commit 26a6338072
6 changed files with 8 additions and 8 deletions

View file

@ -52,7 +52,7 @@ Phaser.PluginManager.prototype = {
*/ */
add: function (plugin) { add: function (plugin) {
var args = Array.prototype.splice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
var result = false; var result = false;
// Prototype? // Prototype?

View file

@ -308,7 +308,7 @@ Phaser.StateManager.prototype = {
if (arguments.length > 2) if (arguments.length > 2)
{ {
this._args = Array.prototype.splice.call(arguments, 2); this._args = Array.prototype.slice.call(arguments, 2);
} }
}, },

View file

@ -414,7 +414,7 @@ Phaser.GameObjectCreator.prototype = {
*/ */
filter: function (filter) { filter: function (filter) {
var args = Array.prototype.splice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
var filter = new Phaser.Filter[filter](this.game); var filter = new Phaser.Filter[filter](this.game);

View file

@ -531,7 +531,7 @@ Phaser.GameObjectFactory.prototype = {
*/ */
filter: function (filter) { filter: function (filter) {
var args = Array.prototype.splice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
var filter = new Phaser.Filter[filter](this.game); var filter = new Phaser.Filter[filter](this.game);

View file

@ -242,7 +242,7 @@ Phaser.Timer.prototype = {
*/ */
add: function (delay, callback, callbackContext) { add: function (delay, callback, callbackContext) {
return this.create(delay, false, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3)); return this.create(delay, false, 0, callback, callbackContext, Array.prototype.slice.call(arguments, 3));
}, },
@ -264,7 +264,7 @@ Phaser.Timer.prototype = {
*/ */
repeat: function (delay, repeatCount, callback, callbackContext) { repeat: function (delay, repeatCount, callback, callbackContext) {
return this.create(delay, false, repeatCount, callback, callbackContext, Array.prototype.splice.call(arguments, 4)); return this.create(delay, false, repeatCount, callback, callbackContext, Array.prototype.slice.call(arguments, 4));
}, },
@ -285,7 +285,7 @@ Phaser.Timer.prototype = {
*/ */
loop: function (delay, callback, callbackContext) { loop: function (delay, callback, callbackContext) {
return this.create(delay, true, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3)); return this.create(delay, true, 0, callback, callbackContext, Array.prototype.slice.call(arguments, 3));
}, },

View file

@ -168,7 +168,7 @@ Phaser.ArraySet.prototype = {
*/ */
callAll: function (key) { callAll: function (key) {
var args = Array.prototype.splice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
var i = this.list.length; var i = this.list.length;