Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个特别基础的js问题 #10

Open
lubyxu opened this issue Aug 25, 2021 · 0 comments
Open

一个特别基础的js问题 #10

lubyxu opened this issue Aug 25, 2021 · 0 comments

Comments

@lubyxu
Copy link
Owner

lubyxu commented Aug 25, 2021

今天碰到了一个问题,__DEV__ is not defined。 想了半天,不知道为什么!!!

__DEV__ 没有的话,不是会一直往上找的么!!直到找到这个为止,找不到默认就是undefined,不应该报错呀!!

但是!!!!我错了。。。
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Not_defined

对于getter来说,如果整条作用域链上没有这个变量,会报 is not defined错误。
但是!对于setter而言。如果整条作用域链 没有这个变量,会做两件事情:

// 1、先在globalThis上声明这个变量
var __DEV__;
// 2、 再对这个变量赋值。
__DEV__ = 1;

!!!!!!!!多么基础的问题啊。。。。。。我居然没想到。。。。。可见生活之中处处是基础。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant