Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
xhr.onreadystatechange вы создаете замыкакание, которое имеет доступ к объявленным переменным, поэтому gc оставляет в памяти переменную xhreval xhr.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
delete xhr;
}var xyz = function(){
console.log('_xyz_');
delete xyz;
}
xyz();
xyz();_xyz_
ReferenceError: xxxyyyzzz is not definedvar a = 10;
b = 20;
delete a;
delete b;
console.log(a); // 10
console.log(b); // ReferenceError: b is not definedvar callback = function() {
if(this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
setInterval(function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'json.txt', true);
xhr.onreadystatechange = callback;
xhr.send('');
}, 500);
var cb = function(d){ var a = 2 + 3; };
setInterval(function(){
$.get('f.txt', cb);
}, 500);
setInterval(function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'json.txt', true);
xhr.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhr.send('');
xhr = null;
}, 500);xhr = new XMLHttpRequest();
xhr.onreadystatechange = callback;
function callback() {
if(xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
};
function request() {
xhr.open('GET', 'json.txt', true);
xhr.send(null);
}
setInterval(request, 500);
var xhr = new XMLHttpRequest();
xhr.open('GET', 'json.txt', true);
xhr.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
setInterval(function(){
xhr.send('');
}, 500);
Простой, казалось бы, вопрос по JavaScript