Как сделать так. чтобы не было таких вызовов как: weather.getRequest(link) и прочее, а было например this.getRequest(link)
Спасибо заранее за ваши ответы!
'use strict'
var weather = {
id: 0,
showWeather: function() {
var target = {
latitude: 0,
longitude: 0
};
function getPosition(position) {
var crd = position.coords;
if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
navigator.geolocation.clearWatch(id)
}
var link = 'http://api.openweathermap.org/data/2.5/weather?lat=' + crd.latitude + '&lon=' + crd.longitude + '&units=metric&lang=ru&appid=b231606340553d9174136f7f083904b3';
weather.getRequest(link);
}
return this.id = navigator.geolocation.watchPosition(getPosition);
},
getRequest: function(link) {
var request = new XMLHttpRequest();
request.open('GET', link , true)
request.onreadystatechange = function(e) {
if (this.readyState == 4) {
if(this.status == 200) {
var response = JSON.parse(this.responseText);
console.log(response);
weather.showWeatherData(response);
}
}
}
request.send(null);
},
showWeatherData: function(response) {
var temp = response.main.temp;
var hum = response.main.humidity;
var descrpt = response.weather[0].description;
temperature.innerHTML = temp;
humidity.innerHTML = hum;
description.innerHTML = descrpt;
},
showCityWeather: function() {
function getPosition() {
var cityName = choiseCityName.value;
var link = 'http://api.openweathermap.org/data/2.5/weather?q=' + cityName + '&units=metric&lang=ru&appid=b231606340553d9174136f7f083904b3';
weather.getRequest(link);
}
navigator.geolocation.clearWatch(this.id)
console.log(this.id)
return this.id = navigator.geolocation.watchPosition(getPosition);
}
}