Skip to content

关于js执行 #15

@uxsi

Description

@uxsi

执行上下文
vo、scope、this

vo:不能直接访问
resolve identifiers

ref:identifiers、property
base、propertyname

excution
enter
excute

enter:初始化(vo 、scope、this)

初始化vo
参数声明
函数声明
变量声明(后于参数与函数声明,在enter阶段不会影响同名的参数与函数声明)

初始化scope
ao+f.[[scope]]

初始化this
global context:global object
function context:ref?(ref.base==ao?global object:base):null,global object
当f作为构造函数被调用时,其base值为新创建的fo,即f中的this为fo

excute
执行代码,对vo上的数据求值(部分vo的属性在此阶段初始化并求值)

闭包
所有函数

函数
函数参数、函数返回值
向下funargs、向上funargs

表达式
不以花括号开头
不以关键字function开头
出现在需要求值的位置

函数表达式:function op:name(){}
(function(){})()
(function(){}())

var o={f:function(){console.log(this)}}
o.f(); //o.f
(o.f)(); //分组操作符没作用,该操作符的值为o.f本身
(1,o.f)(); //分组操作符在这里得到的值是一个函数,函数类型不能赋值,非ref类型

function(){}(); //分解成函数声明function(){}和分组操作();,报函数声明缺少函数名:Unexpected token (
function f(){}();////分解成函数声明function(){}和分组操作();,报分组操作缺少操作数:Unexpected token )

global context
global object在进入代码前已经存在

go={
Boolean:xxx,
Number:xxx,
String:xxx,
Math:xxx;
……
window:go
}

当遇到外部脚本或者script标签时进入global context,进一步初始化go

ref links:
http://weizhifeng.net/javascript-the-core.html
http://www.cnblogs.com/justinw/archive/2010/04/16/1713086.html
http://www.cnblogs.com/justinw/archive/2010/04/23/1718733.html
http://www.cnblogs.com/justinw/archive/2010/05/04/1727295.html
http://dmitrysoshnikov.com/ecmascript/chapter-4-scope-chain
http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/
http://dmitrysoshnikov.com/ecmascript/chapter-6-closures/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions