Skip to content

Commit a070e8d

Browse files
committed
Fix for Event changes
This replaces 'eval' with closures (that should have probably been used to begin with) to avoid warnings generated by some tools. This change does not affect the approach used. - Ref. phaserjs#1494
1 parent 765cab2 commit a070e8d

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

src/gameobjects/Events.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,21 @@ for (var prop in Phaser.Events.prototype)
167167
continue;
168168
}
169169

170-
var backing = 'this._' + prop;
171-
var dispatch = prop + '$dispatch';
172-
173-
// `new Function(string)` is ugly but it avoids closures and by-string property lookups.
174-
// Since this is a [near] micro-optimization anyway, might as well go all the way.
175-
/*jslint evil: true */
176-
177-
// The accessor creates a new Signal (and so it should only be used from user-code.)
178-
Object.defineProperty(Phaser.Events.prototype, prop, {
179-
get: new Function("return "+backing+" || ("+backing+" = new Phaser.Signal())")
180-
});
181-
182-
// The dispatcher will only broadcast on an already-defined signal.
183-
Phaser.Events.prototype[dispatch] =
184-
new Function("return "+backing+" ? "+backing+".dispatch.apply("+backing+", arguments) : null");
170+
(function (prop, backing) {
171+
'use strict';
172+
173+
// The accessor creates a new Signal; and so it should only be used from user-code.
174+
Object.defineProperty(Phaser.Events.prototype, prop, {
175+
get: function () {
176+
return this[backing] || (this[backing] = new Phaser.Signal());
177+
}
178+
});
179+
180+
// The dispatcher will only broadcast on an already-created signal; call this internally.
181+
Phaser.Events.prototype[prop + '$dispatch'] = function () {
182+
return this[backing] ? this[backing].dispatch.apply(this[backing], arguments) : null;
183+
};
184+
185+
})(prop, '_' + prop);
185186

186187
}

0 commit comments

Comments
 (0)