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?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
I think C,D both should be added in the answer list, because the only difference is “this” is assigned into “that” variable, so “D” should also be the correct one.
Unless ‘this’ inside the $.get function will refer to the function object rather than the Customer object.
@nazish you are assuming that this doesn’t change, it does. “this” changes dynamically according to the context, that doesn’t. So set this to that and then change the context which changes this to something else, but you still have the old this because you set it to that.
Answer C: Uncaught TypeError: this.parseAdress is not a function.
IN C this refers to jquery get function:
Object
accepts
:
Object
async
:
true
contentType
:
“application/x-www-form-urlencoded; charset=UTF-8”
contents
:
Object
converters
:
Object
crossDomain
:
false
dataTypes
:
Array[2]
flatOptions
:
Object
global
:
etc. all AJAX options..
FKS is this a dyslexia exam or an HTML5? MS get your priorities straight!
The answer is right. If you use answer D ‘this’ will point to the jQuery get function and not the Customer object. In answer C ‘this’ point to Object{firstName:””, lastName:””, address:””}