2

I deal with nodejs and i cannot figure out, why i cannot call class instance from another class function. Here is my code. Please help.

var StationDAO = require('./StationDAO.js');
var StationSearchCriteria = require('./StationSearchCriteria.js');

function GasStationService(lat, long, zoom) {
this.latitude = lat;
this.longitude = long;
this.zoom = zoom;
this.zoomToKilometers = 0.009;

/* ......... */

this.minLat = function () {
    return this.latitude - this.zoomToKilometers;
};

this.minLong = function() {
    return this.longitude - this.zoomToKilometers;
};

this.maxLat = function() {
    return this.latitude + this.zoomToKilometers;
};

this.maxLong = function() {
    return this.longitude + this.zoomToKilometers;
};

this.criteria = new StationSearchCriteria(this.minLat(), this.minLong(),     this.maxLat(), this.maxLong());
this.conn = new StationDAO(criteria); // why this doesnt work
4
  • Is StationDAO module defined as a single function bound to module.exports? Commented Mar 13, 2014 at 10:06
  • It is class accessing to Elastic search DB and it is module.exports Commented Mar 13, 2014 at 11:13
  • Is there any async code in StationDAO? (maybe something is not yet initialized when you are invoking it). Commented Mar 13, 2014 at 11:22
  • yes, there is one function, but it isnt called. Commented Mar 13, 2014 at 11:25

1 Answer 1

1

you are passing criteria which is not defined i assume you wanted to pass this.criteria isntead.

this.criteria = new StationSearchCriteria(this.minLat(), this.minLong(), this.maxLat(), this.maxLong());
this.conn = new StationDAO(this.criteria); //this should work
Sign up to request clarification or add additional context in comments.

4 Comments

if ` criteria ` is not defined then how this.criteria is existing ?
this.criteria is not the same as criteria. I seriously dont understand your comment.
'this' pointer refers the current object's variable, in the problem statement 'criteria' is a variable which is the instance of StationSearchCriteria class and is already initialized.
+1'd this to bring it to zero since I think someone downvoted it not understanding it. Or maybe I am not understanding. I don't know why someone thinks that foo and this.foo would be the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.