0

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?

2
  • i assume the .'s is just your way of saying there's code there that you've omitted? Commented Apr 15, 2014 at 21:16
  • Yes, the . is omitted code for the sake of secrecy. Commented Apr 15, 2014 at 21:39

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Since, nothing was passed to fooFieldWidgetOptions.changeCallback, does that mean fooModel is undefined? Is it set to a default value?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.