PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an HTML5 web application that displays customer mailing address information. The application loads addresses from a web service by using AJAX.
The following code defines a Customer object and loads address data.

You need to implement the loadAddress function. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
$.get(‘data.xml’, function (data) {
(function (scope) {
scope.parseAddress(data);
})(data);
});

B.
$.get(‘data.xml’, function (data, innerScope) {
innerScope.parseAddress(data);
});

C.
var that = this;
$.get(‘data.xml’, function (data) {
that.parseAddress(data);
}

D.
$.get(‘data.xml’, function (data) {
this.parseAddress(data);
}

6 Comments on “Which code segment should you use?

  1. anii says:

    I think maybe because we want ‘this’ to refer to loadAddress function and not to the function we are writing (function(data))…
    Can anybody tell me if that’s correct?




    0



    0
  2. carol says:

    D is wrong because it gets the current instance or context of the function inside the get request, what we want is the instance or context of the load address method this is why we assign the this keyword to a variable named that. from inside the load address method we perform the get request to the parse address method.




    0



    0

Leave a Reply