I wonder if anyone can help
I have a jQuery plugin with the following code:
....
$.Autocompleter.Select = function (options, input, select, config) {
var list;
....
return {
emptyList: function (){
list && list.empty();
}
}
}
I would like to override the emptyList function; and have written the following code:
originalAutoCompleteSelectFunction = $.Autocompleter.Select;
$.Autocompleter.Select = function (options, input, select, config) {
var ret = originalAutoCompleteSelectFunction.apply(this, arguments);
ret.emptyList = function() {
console.log ("hello");
console.log ("The list=" + list);
};
return ret;
};
It sort of works, but:
- My implementation of emptyList runs - I see 'hello' on the console - but the orignal implementation of emptyList also runs. So its not really an overridden function is it? Its more like an augmentation?
- I dont seem to be able to access the variable 'list'
So, 2 questions. Have I written the code correctly to truely override the existing function? And, is it possible to access the variable 'list'? I know its a private member of the closure, but if you cant access private members in this way presumably it makes the ability to override functions (that use those private members) pointless ?
Or have I missed something?
I've already looked at Extending an existing jQuery function which gave me the steer on how to override functions in this way; and also this Access private members of jQuery plugin which suggests that accessing private members of a closure is not possible.
Cheers
Nathan