-
-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket #108 : added the possibility to pass arguments to the plugin c…
…onstructor (through the register function)
- Loading branch information
obiot
committed
Jan 17, 2013
1 parent
be676fd
commit 981ea57
Showing
2 changed files
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ | |
* @function | ||
* @param {me.plugin.Base} plugin Plugin to instiantiate and register | ||
* @param {String} name | ||
* @param {Object} [args] all extra parameters will be passed to the plugin constructor | ||
* @example | ||
* // register a new plugin | ||
* me.plugin.register(TestPlugin, "testPlugin"); | ||
|
@@ -120,8 +121,16 @@ | |
throw ("melonJS: Plugin version mismatch, expected: "+ plugin.prototype.version +", got: " + me.version); | ||
} | ||
|
||
// get extra arguments | ||
var _args = []; | ||
if (arguments.length > 2) { | ||
// store extra arguments if any | ||
_args = Array.prototype.slice.call(arguments, 1); | ||
} | ||
|
||
// try to instantiate the plugin | ||
me.plugin[name] = new plugin(); | ||
_args[0] = plugin; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
parasyte
Collaborator
|
||
me.plugin[name] = new (plugin.bind.apply(plugin, _args))(); | ||
|
||
// inheritance check | ||
if (!(me.plugin[name] instanceof me.plugin.Base)) { | ||
|
1 comment
on commit 981ea57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was actually linked to ticket #85
This doesn't look right! @obiot can you verify? I think it will actually break the first arg passed to the plugin constructor.