I have a bit of code that has a bit of a foreign syntax to me:
$.widget('ui.filterFieldDisplay', $.ui.fieldDisplay, {
setFoo: function() {
.
.
.
// added the next two lines
var fooFieldWidgetOptions = fooFieldOptions.widgetOptions;
fooFieldWidgetOptions['default'] = operator;
var fooChangeProxy = $.proxy(this.fooChange, this);
fooFieldWidgetOptions.changeCallback = fooChangeProxy;
}
fooChange: function(fooModel) {
fooModel.getValue('bar');
.
.
.
}
});
Is fooModel in this case referenced to the this pointer?
I know that the $.proxy method binds the this pointer to the function, so that it operates within that context. But I know that this doesn't get referenced to fooModel. So my question is: what is fooModel and where does it come from?
asked Apr 15, 2014 at 21:11
tomato
8416 gold badges17 silver badges33 bronze badges
1 Answer 1
No, fooModel will be whatever was passed as the first parameter to fooFieldWidgetOptions.changeCallback
fooFieldWidgetOptions.changeCallback("helloWorld!"); // fooModel will be `helloWorld!`
All $.proxy() did was ensure that this inside of fooChange will be the same as this inside of setFoo
answered Apr 15, 2014 at 21:20
user400654
95.1k16 gold badges168 silver badges188 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
tomato
Since, nothing was passed to
fooFieldWidgetOptions.changeCallback, does that mean fooModel is undefined? Is it set to a default value?user400654
If it is indeed the case that nothing is passed to it, yes, you haven't included that part of your code in your question though so i can't be sure.
tomato
Okay, so is that the only way to pass a variable to
fooChange in my case? Is there other ways? I've edited my code to include more details about how it was called in setFoo.lang-js
.'s is just your way of saying there's code there that you've omitted?.is omitted code for the sake of secrecy.