나는 isRetina
함수를 가지고 있으며 다른 resizeImage()
내에서 결과에 액세스하려고하지만 변수 retinaCheck는 항상 나를 다시 정의하지 않습니다. 글로벌 변수를 처음부터 선언했는데, 왜 그런가?다른 함수 내에서 함수 결과에 액세스하는 중
$(window).load(function() {
function isRetina() {
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 2)) && /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
}
var retinaCheck = isRetina();
});
function resizeImage() {
if ($(window).width() > 649) {
console.log("resize:" + retinaCheck)
}
});
전체 코드를 표시합니다. – Cheery
잘 작동합니다 : http://jsfiddle.net/rx0khzp0/1/ – DhruvPathak
디버깅 도움말 ("이 코드가 작동하지 않는 이유는 무엇입니까?")에는 원하는 동작, 특정 문제 또는 오류 ** 및 가장 짧은 코드가 포함되어야합니다. 질문 자체에서 그것을 재현하는 데 필요한 **. 문제를 재현하는 코드가 없으면 (귀하의 코드는 그렇게하지 않습니다.) - 우리가 당신을 도울 수있는 방법은 거의 없습니다. –