Skip to content

Commit f15fe67

Browse files
committed
All undefined argument checks were changed from if (typeof x === 'undefined') to if (x === undefined) removing the typeof check and saving some bytes across the codebase in the process.
1 parent 9e38bf9 commit f15fe67

88 files changed

Lines changed: 618 additions & 617 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ For the full list of p2 additions please read [their change log](https://github.
409409
* Internally the Time class has been updated to split out the RAF and SetTimeout implementations. This cuts down the update loop workload significantly, which was causing a performance optimization bottleneck in V8.
410410
* TweenData.update now uses the `Time.elapsedMS` value for its delta calculation, instead of the physicsStep - this is because tweens are inherently time duration based and on a lagging system they were not properly completing when they should do (also addresses #1819)
411411
* World.stateChange is a new method that is called whenever the state changes or restarts. It resets the world x/y coordinates back to zero and then resets the Camera.
412+
* All undefined argument checks were changed from `if (typeof x === 'undefined')` to `if (x === undefined)` removing the typeof check and saving some bytes across the codebase in the process.
412413

413414
### Bug Fixes
414415

src/animation/Animation.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
Phaser.Animation = function (game, parent, name, frameData, frames, frameRate, loop) {
2424

25-
if (typeof loop === 'undefined') { loop = false; }
25+
if (loop === undefined) { loop = false; }
2626

2727
/**
2828
* @property {Phaser.Game} game - A reference to the currently running Game.
@@ -246,7 +246,7 @@ Phaser.Animation.prototype = {
246246

247247
var frameIndex;
248248

249-
if (typeof useLocalFrameIndex === 'undefined')
249+
if (useLocalFrameIndex === undefined)
250250
{
251251
useLocalFrameIndex = false;
252252
}
@@ -303,8 +303,8 @@ Phaser.Animation.prototype = {
303303
*/
304304
stop: function (resetFrame, dispatchComplete) {
305305

306-
if (typeof resetFrame === 'undefined') { resetFrame = false; }
307-
if (typeof dispatchComplete === 'undefined') { dispatchComplete = false; }
306+
if (resetFrame === undefined) { resetFrame = false; }
307+
if (dispatchComplete === undefined) { dispatchComplete = false; }
308308

309309
this.isPlaying = false;
310310
this.isFinished = true;
@@ -445,7 +445,7 @@ Phaser.Animation.prototype = {
445445
*/
446446
updateCurrentFrame: function (signalUpdate, fromPlay) {
447447

448-
if (typeof fromPlay === 'undefined') { fromPlay = false; }
448+
if (fromPlay === undefined) { fromPlay = false; }
449449

450450
if (!this._frameData)
451451
{
@@ -485,7 +485,7 @@ Phaser.Animation.prototype = {
485485
*/
486486
next: function (quantity) {
487487

488-
if (typeof quantity === 'undefined') { quantity = 1; }
488+
if (quantity === undefined) { quantity = 1; }
489489

490490
var frame = this._frameIndex + quantity;
491491

@@ -517,7 +517,7 @@ Phaser.Animation.prototype = {
517517
*/
518518
previous: function (quantity) {
519519

520-
if (typeof quantity === 'undefined') { quantity = 1; }
520+
if (quantity === undefined) { quantity = 1; }
521521

522522
var frame = this._frameIndex - quantity;
523523

@@ -770,7 +770,7 @@ Object.defineProperty(Phaser.Animation.prototype, 'enableUpdate', {
770770
*/
771771
Phaser.Animation.generateFrameNames = function (prefix, start, stop, suffix, zeroPad) {
772772

773-
if (typeof suffix === 'undefined') { suffix = ''; }
773+
if (suffix === undefined) { suffix = ''; }
774774

775775
var output = [];
776776
var frame = '';

src/animation/AnimationManager.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Phaser.AnimationManager.prototype = {
8686
*/
8787
loadFrameData: function (frameData, frame) {
8888

89-
if (typeof frameData === 'undefined')
89+
if (frameData === undefined)
9090
{
9191
return false;
9292
}
@@ -102,7 +102,7 @@ Phaser.AnimationManager.prototype = {
102102

103103
this._frameData = frameData;
104104

105-
if (typeof frame === 'undefined' || frame === null)
105+
if (frame === undefined || frame === null)
106106
{
107107
this.frame = 0;
108108
}
@@ -146,7 +146,7 @@ Phaser.AnimationManager.prototype = {
146146
}
147147
}
148148

149-
if (typeof frame === 'undefined' || frame === null)
149+
if (frame === undefined || frame === null)
150150
{
151151
this.frame = 0;
152152
}
@@ -184,10 +184,10 @@ Phaser.AnimationManager.prototype = {
184184
frames = frames || [];
185185
frameRate = frameRate || 60;
186186

187-
if (typeof loop === 'undefined') { loop = false; }
187+
if (loop === undefined) { loop = false; }
188188

189189
// If they didn't set the useNumericIndex then let's at least try and guess it
190-
if (typeof useNumericIndex === 'undefined')
190+
if (useNumericIndex === undefined)
191191
{
192192
if (frames && typeof frames[0] === 'number')
193193
{
@@ -229,7 +229,7 @@ Phaser.AnimationManager.prototype = {
229229
*/
230230
validateFrames: function (frames, useNumericIndex) {
231231

232-
if (typeof useNumericIndex === 'undefined') { useNumericIndex = true; }
232+
if (useNumericIndex === undefined) { useNumericIndex = true; }
233233

234234
for (var i = 0; i < frames.length; i++)
235235
{
@@ -306,7 +306,7 @@ Phaser.AnimationManager.prototype = {
306306
*/
307307
stop: function (name, resetFrame) {
308308

309-
if (typeof resetFrame === 'undefined') { resetFrame = false; }
309+
if (resetFrame === undefined) { resetFrame = false; }
310310

311311
if (typeof name === 'string')
312312
{

src/animation/Frame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Phaser.Frame.prototype = {
212212
*/
213213
getRect: function (out) {
214214

215-
if (typeof out === 'undefined')
215+
if (out === undefined)
216216
{
217217
out = new Phaser.Rectangle(this.x, this.y, this.width, this.height);
218218
}

src/animation/FrameData.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Phaser.FrameData.prototype = {
143143
*/
144144
getFrameRange: function (start, end, output) {
145145

146-
if (typeof output === "undefined") { output = []; }
146+
if (output === undefined) { output = []; }
147147

148148
for (var i = start; i <= end; i++)
149149
{
@@ -166,10 +166,10 @@ Phaser.FrameData.prototype = {
166166
*/
167167
getFrames: function (frames, useNumericIndex, output) {
168168

169-
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
170-
if (typeof output === "undefined") { output = []; }
169+
if (useNumericIndex === undefined) { useNumericIndex = true; }
170+
if (output === undefined) { output = []; }
171171

172-
if (typeof frames === "undefined" || frames.length === 0)
172+
if (frames === undefined || frames.length === 0)
173173
{
174174
// No input array, so we loop through all frames
175175
for (var i = 0; i < this._frames.length; i++)
@@ -213,10 +213,10 @@ Phaser.FrameData.prototype = {
213213
*/
214214
getFrameIndexes: function (frames, useNumericIndex, output) {
215215

216-
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
217-
if (typeof output === "undefined") { output = []; }
216+
if (useNumericIndex === undefined) { useNumericIndex = true; }
217+
if (output === undefined) { output = []; }
218218

219-
if (typeof frames === "undefined" || frames.length === 0)
219+
if (frames === undefined || frames.length === 0)
220220
{
221221
// No frames array, so we loop through all frames
222222
for (var i = 0; i < this._frames.length; i++)

src/core/Camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Phaser.Camera.prototype = {
163163
*/
164164
follow: function (target, style) {
165165

166-
if (typeof style === "undefined") { style = Phaser.Camera.FOLLOW_LOCKON; }
166+
if (style === undefined) { style = Phaser.Camera.FOLLOW_LOCKON; }
167167

168168
this.target = target;
169169

src/core/Create.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Phaser.Create.prototype = {
5151

5252
texture: function (key, data, pixelWidth, pixelHeight, palette) {
5353

54-
if (typeof pixelWidth === 'undefined') { pixelWidth = 8; }
55-
if (typeof pixelHeight === 'undefined') { pixelHeight = pixelWidth; }
56-
if (typeof palette === 'undefined') { palette = 0; }
54+
if (pixelWidth === undefined) { pixelWidth = 8; }
55+
if (pixelHeight === undefined) { pixelHeight = pixelWidth; }
56+
if (palette === undefined) { palette = 0; }
5757

5858
var w = data[0].length * pixelWidth;
5959
var h = data.length * pixelHeight;

src/core/FlexGrid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Phaser.FlexGrid.prototype = {
112112
*/
113113
createCustomLayer: function (width, height, children, addToWorld) {
114114

115-
if (typeof addToWorld === 'undefined') { addToWorld = true; }
115+
if (addToWorld === undefined) { addToWorld = true; }
116116

117117
this.customWidth = width;
118118
this.customHeight = height;
@@ -147,7 +147,7 @@ Phaser.FlexGrid.prototype = {
147147
*/
148148
createFluidLayer: function (children, addToWorld) {
149149

150-
if (typeof addToWorld === 'undefined') { addToWorld = true; }
150+
if (addToWorld === undefined) { addToWorld = true; }
151151

152152
var layer = new Phaser.FlexLayer(this, this.positionFluid, this.boundsFluid, this.scaleFluid);
153153

src/core/Game.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ Phaser.Game.prototype = {
439439

440440
this.config = config;
441441

442-
if (typeof config['enableDebug'] === 'undefined')
442+
if (config['enableDebug'] === undefined)
443443
{
444444
this.config.enableDebug = true;
445445
}

0 commit comments

Comments
 (0)