function Class(){
this.result;
}
Class.prototype.get = function(){
play();
function play(){
/*Запросы, выполняются какое-то время*/
setTimeout(function(){
this.result = 'array';
}, 1500);
}
return this.result;
}
c = new Class();
r = c.get();
// необходимо чтобы в r уже лежал array
console.log(r); function Class(){
this.result;
}
Class.prototype.get = function(){
var dfd = new jQuery.Deferred();
play();
function play(){
/*Запросы, выполняются какое-то время*/
setTimeout(function(){
this.result = 'array';
dfd.resolve(this.result);
}, 1500);
}
return dfd.promise();
}
c = new Class();
$.when(c.get()).done(function(res) {
var r = res;
console.log(r);
});
function Class(){
this.result;
}
Class.prototype.get = function(onComplete){
play();
function play(){
/*Запросы, выполняются какое-то время*/
setTimeout(function(){
this.result = 'array';
onComplete(this.result);
}, 1500);
}
}
c = new Class();
c.get(
function(result){ console.log(result); }
);
// необходимо чтобы в r уже лежал array