I am fairly new with JS object contructors and I seem to have a problem here, either with how I construct the object, scope or both. The myService method does create two new properties, response and status, however when I try to access those properties they are "undefined" and I am not sure why.
var n = new myPlaces(map, myOptions);
var z = n.places();
console.log(z); // returns object with all properites
console.log(z.response) //undefined
console.log(z.status) // undefined
function myPlaces(map, myOptions) {
this.map = map;
this.myOptions = myOptions;
};
myPlaces.prototype = {
construtor: myPlaces,
myService: function() {
var self = this;
this.service = new google.maps.places.PlacesService(this.map);
this.service.nearbySearch(this.myOptions.request, function(results, status) {
self.response = results; //response: Array[20]
self.status = status; //status: "OK"
});
return self;
},
places:function() {
return this.myService();
}
};