其他类函数中的Javascript类实例(nodejs)

时间:2014-03-13 09:57:27

标签: javascript node.js oop

我处理nodejs,我无法弄清楚,为什么我不能从另一个类函数调用类实例。这是我的代码。请帮忙。

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

1 个答案:

答案 0 :(得分:1)

您正在传递未定义的标准我假设您想要传递this.criteria isntead。

this.criteria = new StationSearchCriteria(this.minLat(), this.minLong(), this.maxLat(), this.maxLong());
this.conn = new StationDAO(this.criteria); //this should work