How about this? :
var Toolbar = {
init: function(toolbar) {
this.Bar = $(toolbar); // scope is Toolbar object literal
this.trigger =
function() { this.Bar.trigger.apply(this.Bar, arguments); };
this.bind = function() { this.Bar.bind.apply(this.Bar, arguments); };
this.Bar.find('clearButton').click(function() {
this.trigger('clear');
}
};
Toolbar.init();
Toolbar.bind('clear', function() { ... });
If you want, you can readily create a function to handle the wrapping; either of these, as you prefer:
function wrapperitize(wrapper, wrappee, method /*, more_methods...*/)
{
wrapper[method] = function() { wrappee[method].apply(wrappee, arguments); };
for(var i = 3; i < arguments.length; ++i)
wrapperitize(wrapper, wrappee, arguments[i]);
}
function wrapperitize(wrapper, wrappeeProp, method /*, more_methods...*/)
{
wrapper[method] = function()
{
wrapper[wrappeeProp][method].apply(wrapper[wrappeeProp], arguments);
};
for(var i = 3; i < arguments.length; ++i)
wrapperitize(wrapper, wrappeeProp, arguments[i]);
}
where the former would be called as wrapperitize(this, this.Bar, 'trigger', 'bind')
and the latter as wrapperitize(this, 'Bar', 'trigger', 'bind')
(the difference being that the former will make this
into a wrapper for whatever this.Bar
currently is, whereas the latter will make this
into a wrapper for whatever this.Bar
might ever become in the future.
(Note, by the way, the tiny bit of recursion. This is to avoid problematic variable capture, due to the way closures work in JavaScript.)