Command inheritance

1 view
Skip to first unread message

Eugene Janusov

unread,
Jan 3, 2009, 12:20:17 AM1/3/09
to ubiquity-firefox
I have several very similar commands. So I'd like to make a base
command with shared functionality, and the rest of commands should
“inherit” from it.

Test code:

var MyCommands = {};
MyCommands['stub-command'] = {
author: {
name: "Eugene Janusov",
email: "esy...@gmail.com"
},

preview: function(pblock, directObject) {
displayMessage('::: ' + this.test());
},

execute: function(directObject) {},

test: function() {
return '[' + this.name + '] [' + this.author.name + ']';
}

};

MyCommands['test-command'] = jQuery.extend({}, MyCommands['stub-
command'], {
name: 'test-command'
});

CmdUtils.CreateCommand(MyCommands['test-command']);

displayMessage('::: ' + MyCommands['test-command'].test());
MyCommands['test-command'].preview();


The last two lines work perfectly, display
::: [test-commands] [Eugene Janusov]
>>> [test-commands] [Eugene Janusov]

But as soon as I start to use `test-command', I get the following
message:
>>> [] [Eugene Janusov]

Seems like Ubiquity calls preview() in some special context.
Is there any way to “extend” commands?

Blair McBride

unread,
Jan 13, 2009, 9:44:34 PM1/13/09
to ubiquity...@googlegroups.com
Currently there's no way of inheriting from/extending commands in the
way you've described here. However, you could just split the shared code
into its own function in the global scope of the feed, and have the
commands use that. Since each command feed is executed in its own
sandbox, you won't need to worry about naming collisions with other
command feeds.

Command object introspection is a bit impossible to do at the moment, as
everything gets wrapped in one or two extra layers before being put into
the resulting command object. Its something that needs fixed sometime.

- Blair
Reply all
Reply to author
Forward
0 new messages