以下内容到底是如何输出“未定义”而不是“数字”?
<script>
var foo = {
bar: function(){ return this.baz; },
baz: 1
}
console.log(typeof (f = foo.bar)());
</script>
Note: The code is exactly right and not a typo. I mean (f = foo.bar)() only here which is a valid code.
最佳答案
因为在执行时,上下文是“window”,所以window对象上没有声明变量“baz”。
关于javascript - 为什么输出给出 'undefined' 而不是 JS 示例中的 'number'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54880743/