1
我有這樣的代碼:我正在爲什麼我得到ReferenceError:_variable沒有定義?
sw = {}
sw.photoswipe = {
settings: {
screenWidths: [1024, 1280, 1440, 1680, 1920, 2560, 2880, 3840],
screenHeights: [ 768, 800, 900, 1050, 1200, 1600, 1800, 2400],
_pixelRatio: window.devicePixelRatio || 1,
// this line is where the error happens
_screenWidth: window.screen.width * _pixelRatio,
_screenHeight: window.screen.height * _pixelRatio,
getScreenSizeDescription: function() {
return _screenWidth.toString() + 'x' + _screenHeight;
},
...
}
}
錯誤是:
12:37:09.471 ReferenceError: _pixelRatio is not defined 1
它是正確的上述定義。爲什麼錯誤?請解釋。