I am currently working with prototype 1.7 and developing a class that is designed to take a list of divs and create a tab interface.
var customTabs = Class.create({
initialize: function(container, options) {
this.options = Object.extend({
// additional options
tabsLoaded: null,
}, options || {});
// initialization code
if( this.options.tabsLoaded ) {
this.options.tabsLoaded();
}
},
// other methods
setCurrentTab: function(link){
// adds a .current class to the clicked tab and its corresponding section
}
};
new customTabs( 'products', {
tabsLoaded: function(){
if( window.location.hash != "" ) {
var link = $$( 'a[href$="' + window.location.hash + '"]');
this.setCurrentTab(link);
}
}
});
I have a question regarding my tabsLoaded custom callback. When the callback is executed, this.setCurrentTab(link)
does not work as expected.
If I pass this into the callback, everything works fine.
if( this.options.tabsLoaded ) {
this.options.tabsLoaded(this);
}
I believe that passing this into the callback may not be the recommended practice. So, how can I grant access to a method from within a callback?
Thank you!