Timeline for Scope in an $.ajax callback function
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 3, 2012 at 20:16 | history | edited | slashingweapon | CC BY-SA 3.0 |
update explanation to match the revised code
|
Nov 3, 2012 at 20:07 | comment | added | bconrad | Perfect. That does it. Thanks for sticking with me. | |
Nov 3, 2012 at 20:06 | vote | accept | bconrad | ||
Nov 3, 2012 at 17:41 | comment | added | slashingweapon |
If you need to use the passed-in function, then you want to use onComplete.call(this, data); That is the same as this.doStuff() , except that you can use the passed-in function no matter what it is.
|
|
Nov 3, 2012 at 17:33 | comment | added | bconrad |
I appreciate your help and maybe I am missing something but your example isn't using the onComplete callback. It is calling doStuff directly. If you change this.doStuff(data) to onComplete(data) , (this === c$.oTestScope) will return false. I agree that your syntax is much cleaner. If I can get it to work I'll use it.
|
|
Nov 2, 2012 at 21:43 | comment | added | slashingweapon |
I know you've already chosen your solution, but please give this revision a look. It cleanly fixes your problem with this without having to use any extra closures or temporary variables.
|
|
Nov 2, 2012 at 21:42 | history | edited | slashingweapon | CC BY-SA 3.0 |
Improvements, fiddle, and comments.
|
Nov 2, 2012 at 16:51 | comment | added | bconrad | The context option only seems to work when you call the function directly "context:onComplete". I can't see any way that you can have default functionality as well as callback functionality using this method. Here is that jsfiddle with the context option jsfiddle.net/RW4Ge/2. | |
Nov 2, 2012 at 16:35 | history | answered | slashingweapon | CC BY-SA 3.0 |