重读犀牛书,很多以前没概念的东西,都有点感觉了。重读书真是一种乐趣呀。
这次看到execution context、scope chain、call object的概念,感觉还是理解得不太透彻,不过先简要总结一下。
1.每个函数执行的时候,都会有一个execution context,即执行上下文。不在function内的代码(姑且称作全局代码)执行时,有个global上下文;function中的代码执行时,也有独立的执行上下文。
2.每个执行上下文都关联一个scope chain,这个scope chain是包含一个或者多个对象的链。对于在function外执行的代码,它的scope chain上只有一个全局对象(global object)。无嵌套函数的scope chain上有2个对象,第一个是该函数的call object(调用对象),第二个才是global object。如果是一个function内的嵌套函数,那么chain上就有3个对象了。
3.所有全局变量和function,都是global object的属性。然后function的参数和局部变量是call object的属性。嵌套函数的参数和局部变量,是嵌套的call object的属性。(这个call object是scope chain的第一个对象,第2个对象是外层的call object,然后才轮到global object)
4.所以外层function是访问不到嵌套function的局部变量的,因为它的scope chain上只有它自己的call object和global object,而嵌套function的局部变量,是内层call object的属性,所以在外层是访问不到的。总结:function只能找到在scope chain里的对象的属性。
其他内容,以后再补充。
分享到:
相关推荐
官方版本,亲测可用
const Context = require ( 'node-execution-context' ) ; const UserController = require ( './controllers/user' ) ; const app = express ( ) ; const port = 3000 ; const ContextMiddlewa
目录安装$ npm install @mondaydotcomorg/node-execution-context或与纱线: $ yarn add @mondaydotcomorg/node-execution-context入门让我们创建一个将使用我们的库来创建和获取上下文的服务。 const context...
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
Manufacturing Execution Systems – MES Dr.-Ing. Jürgen Kletti Springer Berlin Heidelberg PDF 英文版。解释、建构 MES,最后其中一章谈到与SAP 集成,和塑料加工行业MES 应用。 专门谈 MES 的书其实不多,这本...
import scala.concurrent.ExecutionContext.Implicits.global object Main extends App { implicit val akkaSystem = akka.actor.ActorSystem() val redis = RedisClient() val futurePong = redis....
Rust的执行上下文 这实现了.NET启发的执行上下文。...let ec = ExecutionContext :: capture (); TEST. set ( 23 ); assert_eq! ( * TEST. get (), 23 ); ec. run ( || { assert_eq! ( * TEST. get
be configured by domain experts external to the execution of the program. These systems are important when flexibility and dynamic runtime configuration is needed, but their architectures have yet to ...
Asynchronous Query Execution异步查询