-
Notifications
You must be signed in to change notification settings - Fork 292
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
lesson4文件中 var success = prepare();的执行细节 #481
Comments
问题3:如果将29行的"var success = prepare();"放到函数外(例如前面的26行),那success是不是就变成全局变量了?整个代码执行起来也是一样的,只不过这个success也可以被其他函数用了?这就是老师今晚提到的作用域么? |
mdqsky
changed the title
JS课程问题- var success = prepare();的执行细节
lesson4/kitchen_workflow.js文件中 var success = prepare();的执行细节
Sep 1, 2017
mdqsky
changed the title
lesson4/kitchen_workflow.js文件中 var success = prepare();的执行细节
lesson4文件中 var success = prepare();的执行细节
Sep 1, 2017
新的发现今天用昨晚老师教的console.log(n);理解程序运行顺序,感觉头脑里的逻辑更清晰了,十分感谢!又测试了问题3的变体,发现把29行放出来后,prepare()会先于startWork()执行,似乎会改变程序设计时的本意。相比只是一个数组、字符串之类的局部变量变成全局变量,影响更大,要考虑的点也更多。 |
是不是问题都解决了? |
并不是完全清楚,还是希望能点评一下 发自网易邮箱大师 在2017年09月02日 17:53,xugaoyang 写道: 是不是问题都解决了? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JS课程问题- var success = prepare();的执行细节
函数来源:
getting-started-with-javascript/study/lesson4/kitchen_workflow.js
问题1:
第29行的"var success = prepare();"具体的执行过程是怎样的?
原本我想着这句话只是定义变量success,并将prepare()的return赋值给success。
但我测试后的感觉是:
正确的理解应该是怎样的?
问题2:
接着上一个问题:在实际项目中,有没有一种可能的情况,prepare()函数在其他地方已经执行过了,此处并不想再执行一遍,只需要知道它的return,以便赋给success后做下面(31行)的判断语句。
如果有这种情况,应该怎样改动?我联想到2种可能性
The text was updated successfully, but these errors were encountered: