I am using a jQuery Class plugin as so :
jQuery(document).ready(function($) {
window.SSK.calendar = new(Class.extend({
filter_by_filtered_names: function() {
console.log('foobar!');
},
init: function() {
if ( window.location.href.match(/name_filters/) ) {
SSK.calendar.filter_by_filtered_names();
};
}
}))
});
For some reason this returns on load :
SSK.calendar is undefined
Which tells me that the plugin class is not loading before its own call. Very strange indeed. Curious if anyone knew a remedy?
The behaviour seems to make perfect sense to me, even if I don’t know how
Classworks:Class.extend(...)creates a new constructor function (I assume).newexecutes the constructor which in turn callsinit. The result is assigned towindow.SSK.calendar. You see,initis called upon instantiation and this happens before the instance is assigned towindow.SSK.calendar.Here is a simplified example:
This will fail since
foois stillundefinedat the moment the constructor is called. The instance is the return value of the function call, hencefoocannot contain a reference to the instance before the call.You might be able to solve your problem by simply using
thisto reference the instance:The documentation of the plugin should mention how you can reference the instance from inside a method.