Skip to content

Commit e711559

Browse files
Add/use init methods for ScriptType and EventHandler (playcanvas#2879)
* Add/use init methods for ScriptType and EventHandler * Reorder imports Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent 135c8fe commit e711559

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/core/event-handler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
*/
1717
class EventHandler {
1818
constructor() {
19+
this.initEventHandler();
20+
}
21+
22+
initEventHandler() {
1923
this._callbacks = { };
2024
this._callbackActive = { };
2125
}

src/script/script-type.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ var funcNameRegex = new RegExp('^\\s*function(?:\\s|\\s*\\/\\*.*\\*\\/\\s*)+([^\
4848
class ScriptType extends EventHandler {
4949
constructor(args) {
5050
super();
51+
this.initScriptType(args);
52+
}
5153

54+
initScriptType(args) {
5255
var script = this.constructor; // get script type, i.e. function (class)
5356

5457
// #ifdef DEBUG

src/script/script.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EventHandler } from '../core/event-handler.js';
2+
13
import { ScriptHandler } from '../resources/script.js';
24

35
import { script } from '../framework/script.js';
@@ -61,7 +63,8 @@ function createScript(name, app) {
6163
throw new Error('script name: \'' + name + '\' is reserved, please change script name');
6264

6365
var scriptType = function (args) {
64-
ScriptType.call(this, args);
66+
EventHandler.prototype.initEventHandler.call(this);
67+
ScriptType.prototype.initScriptType.call(this, args);
6568
};
6669

6770
scriptType.prototype = Object.create(ScriptType.prototype);

0 commit comments

Comments
 (0)