其他类函数中的Javascript类实例(nodejs)
我处理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
你传递的标准是没有定义我假设你想通过this.criteria isntead。
this.criteria = new StationSearchCriteria(this.minLat(), this.minLong(), this.maxLat(), this.maxLong()); this.conn = new StationDAO(this.criteria); //this should work