아래의 자바 스크립트에서 위도 (위도) 변수를 인쇄하려고합니다.다른 함수에서 변수를 사용하는 방법은 무엇입니까?
어떻게 위 변수를 참조 할 수 있습니까? this.lat, that.lat, vicinity.lat
등? 내 자바 스크립트에서
나는 당신이 거의 거기
var Vicinity = function (pubReference, sessionId, done, err) {
this.ad = {
getBannerHtml: function() {
console.log(this.lat); // how do I refer to the lat variable?
}
};
this.init = function (done, err) {
var that = this;
this.getLatLng(that, function (position) {
that.lat = position.coords.latitude;
}, err);
if (typeof done === 'function')
done(this);
};
this.init(done, err);
};
$(document).ready(function() {
var data = new Vicinity(pubReference, sessionId,
function (result) {
$("#sticky").html(result.ad.getBannerHtml());
}
);
});
, 즉는 상위 페이지와 같은 도메인에, 당신은 http://stackoverflow.com/questions/17142285/access-iframe 그것을 내에서 변수에 액세스 할 수 없습니다 -content-parent-jquery –
'getBannerHtml'에서'this'가'Vicinity'를 참조하거나'Vicinity'에 의해 인스턴스를 생성 한 것으로 생각된다면, this.ad 객체를 참조하는 것입니다. 그래서 이것을 이것을'that' 변수에 넣으면 더 좋을 것입니다. Look at [Demo] (http://jsfiddle.net/GKDev/U5xZ4/) – Givi
함수에서 getBannerHtml : function() lat 및 lon 변수를 어떻게 참조 할 수 있습니까? 이거. 그거. 그거. 슬림, 인근. 아빠? – grabury