Where I missed a mistake?

Good evening.

Where I missed an error... How to fix?
This API Yandex Maps.

Error: ymapnew.js:33 Uncaught ReferenceError: is not defined DeliveryCalculator
at ymaps.ready (ymapnew.js:33)


In advance Thank You very much!

ymaps.ready(() => {
 let map = new ymaps.Map('map', {
 center: [60.906882, 30.067233],
 zoom: 9,
 type: 'yandex#map',
 behaviors: ['scrollZoom', 'drag'],
 controls: []
}),
 // Address of starting point
 searchStartPoint = new ymaps.control.SearchControl({
 options: {
 useMapBounds: true,
 noPlacemark: true,
 noPopup: true,
 placeholderContent: 'Address of the initial point',
 size: 'large',
},
}),
 // The endpoint address
 searchFinishPoint = new ymaps.control.SearchControl({
 options: {
 useMapBounds: true,
 noCentering: true,
 noPopup: true,
 noPlacemark: true,
 placeholderContent: 'Address endpoint',
 size: 'large',
 float: 'none',
 position: {left: 10, top: 44},
},
}),

 calculator = new DeliveryCalculator(map, map.getCenter());

map.controls.add(searchStartPoint);
map.controls.add(searchFinishPoint);


 searchStartPoint.events.add('resultselect', (event) => {
 let result = searchStartPoint.getResultsArray(),
 selected = event.get('index'),
 point = result['selected'].geometry.getCoordinates();

calculator.setStartPoint(point);
 }).add('load', (event) => {
/*
 * Skip across the field define what it is not reloading data.
 * By getRusultsCount determined that there is at least 1 result
*/

 if (!event.get('skip') && searchStartPoint.getResultsCount())
searchStartPoint.showResult(0)
});

 searchFinishPoint.events.add('resultselect', (event) => {
 let result = searchFinishPoint.getResultsArray(),
 selected = event.get('index'),
 point = result['selected'].geometry.getCoordinates();

calculator.setFinishPoint(point);
 }).add('load', (event) => {
/*
 * Skip across the field define what it is not reloading data.
 * By getRusultsCount determined that there is at least 1 result
*/

 if (!event.get('skip') && searchFinishPoint.getResultsCount())
searchFinishPoint.showResult(0)
});



 // Write the calculator
 DeliveryCalculator = (map, finish) => {
this._map;
 this._start = null;
 this._route = null;

 map.events.add('click', this._onClick, this);
};

 const ptp = DeliveryCalculator.prototype;


 ptp._onClick = (event) => {
 if (this._start)
this.setFinishPoint(event.get('coords'));
else
this.setStartPoint(event.get('coords'));
};

 ptp._onDragEnd = (event) => {
this.getDirection();
};

 ptp.getDirection = () => {
 if (this._route)
this._map.geoObjects.remove(this._route);

 if (this._start && this._finish) {
 const self = this,
 start = this._start.geometry.getCoordinates(),
 finish = this._finish.geometry.getCoordinates();

 ymaps.geocode(start, {results:1}).then((geocode) => {
 let address = geocode.geoObjects.get(0) && geocode.geoObjects.get(0).properties.get('balloonContentBody') || ";

 ymaps.route([start, finish]).then((router) => {
 let distance = Math.round(router.getLength() / 1000),
 message = '<span>Distance: '+ distance + 'km</span><br />' +
 '<span style="font-weight: bold; font-style: italic">cost of delivery: %of SP.</span>';


 self._route = router.getPaths();
 self._route.options.set( {strokeWidth: 5, strokeColor: '0000ffff', opacity: 0.5 });
self._map.getObjects.add(self._route);
 self._start.properties.set('balloonContentBody', address + message.replace('%s', self.calculate(distance)));

});
});

self._map.setBounds(self._map.geoObjects.getBounds())
}
};

 ptp.setStartPoint = (position) => {
 if (this._start)
this._start.geometry.setCoordinates(position);
 else {
 this._start = new ymaps.Placemark(position, { iconContent: 'A' }, { draggable: true });
 this._start.events.add('dragend', this._onDragEnd, this);
this._map.geoObjects.add(this._start);
}

 if (this._finish)
this.getDirection();
};

 ptp.setFinishPoint = (position) => {
 if (this._finish)
this._finish.geometry.setCoordinates(position);
 else {
 this._finish = new ymaps.Placemark(position, { iconContent: 'B' }, { draggable: true });
 this._finish.events.add('dragend', this._onDragEnd, this);
this._map.geoObjects.add(this._finish);
}

 if (this._start)
this.getDirection();
};



 ptp.calculate = (len) => {
 const DELIVERY_TARIF = 20,
 MINIMUM_COST = 500;

 return Math.max(len * DELIVERY_TARIF, MINIMUM_COST);
};








});
March 12th 20 at 08:08
1 answer
March 12th 20 at 08:10
Solution
Ad DeliveryCalculator move it above declare a variable calculator, or replace the function expression in the function declaration.

UPD. You have it in the constructor it calls a method added to the prototype... Carry above everything, not only the Declaration of a function, but a modification of its prototype.
Thank you! - Elias18 commented on March 12th 20 at 08:13

Find more questions by tags JavaScript