I am trying to assign a object to a prototype, but I keep getting a error that the object is undefined. I am trying to do this
//x.prototype.y = {};
StreetEasy.prototype.neighborhoodPaths = {};
and at a later point in the code I am trying to access this object in another prototype function and push in new data with
//x.prototype.assignData = function(z, a){
// this.y[z] = a;
//}
StreetEasy.prototype.findNeighborhoodPath = function(areaQuery, callback){
var data = {q: areaQuery, key: this.apiKey, format: this.format};
var query = qs.stringify(data);
var url = AreaSearchUrl + '?' + query;
var areaQ = areaQuery.toLowerCase();
if (this.neighborhoodPaths[areaQ]) {
callback(this.neighborhoodPaths[areaQ].path);
} else {
http.get(url, function(response){
response.setEncoding('utf8');
response.on('data', function (rData){
rData = JSON.parse(rData);
callback(rData);
rData.areas.every(function(element){
-----------error is here-> this.neighborhoodPaths[element.name.toLowerCase()].path = element.path;
});
}).on('error', function(e){
console.error('ERROR: ' + e.message + ' | ' + e.statusCode );
});
});
}
};
Node keeps returning
TypeError: Cannot read property z of undefined. What am I doing wrong?
Edit more of the code:
StreetEasy.prototype.neighborhoodPaths = {};
StreetEasy.prototype.findNeighborhoodPath = function(areaQuery, callback){
var data = {q: areaQuery, key: this.apiKey, format: this.format};
var query = qs.stringify(data);
var url = AreaSearchUrl + '?' + query;
var areaQ = areaQuery.toLowerCase();
if (this.neighborhoodPaths[areaQ]) {
callback(this.neighborhoodPaths[areaQ].path);
} else {
http.get(url, function(response){
response.setEncoding('utf8');
response.on('data', function (rData){
rData = JSON.parse(rData);
callback(rData);
rData.areas.every(function(element){
-----------error is here-> this.neighborhoodPaths[element.name.toLowerCase()].path = element.path;
});
}).on('error', function(e){
console.error('ERROR: ' + e.message + ' | ' + e.statusCode );
});
});
}
};