有人可以解释为什么这不起作用?检查typeOf undefined无法正常工作?
setOrientation: function() {
if (typeof oldOrientation !== 'undefined') console.log(oldOrientation);
let oldOrientation = orientation;
//other code
}
This throwbacks oldOrientation is undefined
。我最终只是删除了let
,它开始工作,但我很难完全理解为什么。我认为这与范围界定有关?
我已经通过在全球声明oldOrientation
解决了这个问题,我只是想明白为什么typeof
的比较没有按照原来的方式工作。
因为你在函数内部定义它,使之成为全局函数。 – epascarello
但不管怎么样,它不应该比较已经返回'“undefined”,因此不会出现错误? –
吊装....... – epascarello