Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Majid Mokhtari
10,506 PointsHow can I change the scope of callback on AJAX request?
Hello! What does it mean to change the scope of callback!?. And anybody knows how I can change the execution scope of the callback for the ajax request below?
function aName(){ return $.get('/lol-ajax/echo', { random:1}) } function customDfd(){ var dfd = $.Deferred(); setTimeout(function(){ dfd.resolve('all done!'); }, 4000); return dfd.promise(); } $.when(aName(), customDfd()) .done(function(name, custom){ console.log(name[0], custom); });
2 Answers

Iain Simmons
Treehouse Moderator 32,302 PointsFirst up, please wrap any code with three backticks (usually to the left of the number 1 key on your keyboard), each on their own line, and with a blank line proceeding it. You can also specify the type of code for the syntax highlighting:
e.g. this:
```js
var myJavaScriptCode = function() {
console.log("My string");
};
```
will appear like this:
var myJavaScriptCode = function() {
console.log("My string");
};
As for your actual question, you might want to check out jQuery's proxy() method. It looks like it might help with what you're trying to achieve.

Majid Mokhtari
10,506 PointsThank You! it was very helpful