내 자바 프로토 타입 기능은 아래와 같습니다.prototype 함수가 javascript에서 아무 것도 반환하지 않는 이유는 무엇입니까?
ServerDataEngine.prototype.ExecuteCommand = function(command)
{
try
{
var result;
$.get(command, function (data) {
result = jQuery.parseJSON(atob(data));
console.log(result);
});
return result;
}
catch (Exception)
{
throw (new Exception("Can not connect to server"));
}
}
그리고 나는이 함수를 이렇게 부릅니다. ExecuteCommand
에서
ServerDataEngine.prototype.ExecuteQuery = function (query)
{
console.log(this.ExecuteCommand(query));
}
, 다 좋아하지만, ExecuteQuery
에, console.log(this.ExecuteCommand(command))
라인은 undefined
을 생산하고 있습니다.
무엇이 문제입니까?
비동기 자바 스크립트의 세계에 오신 것을 환영합니다! * 비동기 작업 결과를 * 반환 할 수없는 곳. 비동기 JS에 대해 연구하고 콜백 *이 반환 대신 사용되는 방법을 시험해보십시오. – Joseph
[AJAX 함수에서 변수가 반환되지 않음] 가능한 복제본 (http://stackoverflow.com/questions/12475269/variable-doesnt-get-returned-from-ajax-function) –
.done() 후 .get() – steo