/
di_done.js
67 lines (54 loc) · 1.56 KB
/
di_done.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
///////////////////////////////////////////
// Create a Mock or Dummy LatLongService
function DummyLatLongService(){
}
DummyLatLongService.get = function(zip){
this.lat = '38.272689';
this.long = '-76.289063';
};
///////////////////////////////////////////
// Create a LatLongService
function LatLongService(){
}
LatLongService.get = function(zip){
// save this point in scope
// so then call back below can use it.
var _self = this;
// pseudo code
// returns a JQuery Promise
return $.ajax({url: 'http://getit.com'})
.then(function(data){
_self.lat = data.lat;
_self.long = data.long;
});;
};
///////////////////////////////////////////
// Create a Location
function Location(street, city, state, zip, LatLongService){
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
this.getCoordinates(LatLongService);
};
Location.prototype.getCoordinates = function(LatLongService){
LatLongService.get.bind(this);
LatLongService.get(this.zip);
};
///////////////////////////////////////////
// Create a Person with an address and Profile.
function Person(address, fname, lname, dob){
this.address = address;
this.fName = fname;
this.lName = lname;
};
var address1 = new Location('33 Main St', 'Melrose', 'MA', '09849', DummyLatLongService);
var joe = new Person(address1, 'joe', 'smoe');
console.log('joe is ');
console.log(joe);
var tom = new Person(address1,'tom', 'smith');
console.log('tom is ');
console.log(tom);
var liz = new Person(address1,'liz', 'jones');
console.log('liz is ');
console.log(liz);