js补充预编译递归

递归

1.找规律

2.找出口

预编译

js执行三部

  • 语法分析
  • 预编译
  • 解释一行执行一行

预编译

  1. 函数声明整体提升
  2. 变量      声明提升
  • imply global 暗示性全局变量 ,即任何变量,如果变量未经声明就赋值,次变量就为全局对象所有。
function f()
{
    var a = b = 123;
}
console.log(b);
//123    b是全局变量
  • 一切声明的全局变量,全是window的属性。
var a = 123; 
window.a = 123;

window就是全局


预编译过程


1.创建AO(Activation Object)对象,执行期上下文
2.找形参和变量声明,将变量和形参名作为AO属性名,值为undefined
AO{
    a:undefined;
    b:undefined;
}
3.将实参值和形参统一
AO{
    // 把1传进来
    a:1;
    b:undefined;
}
4.在函数体里面找到函数的声明,值赋予函数体。
AO{
    a:function a(){};
    b:undefined;
    d:function d(){};
}
 

function fn(a){
	console.log(a);
	// function a(){}
	var a = 123;
	
	console.log(a);
	// 123
	function a(){}
	
	console.log(a);
	// 123
	var b = function(){}
	
	console.log(b);
	// function(){}
	function d(){}
}
fn(1);
//预编译发生在函数执行的前一刻

AO{
    a:undefined;
    b:undefined;
    c:undefined;
}

AO{
    a:1;
    b:undefined;
    c:undefined;
}

AO{
    a:1;
    b:function b(){};
    c:undefined;
    d:function d(){};
}
 

function test(a,b){
	concole.log(a);
	// 1
	c = 0;
	var c;
	a = 3;
	b = 2;
	concole.log(b);
	// 2
	function b(){};
	function d(){};
	concole.log(b);
	// 2
}
test(1);

全局

1.生成了一个GO对象Global Object
GO {
    a:undefined;
}

GO {
    a:function a();
}
GO === window


console.log(a);//function a(){}
var a = 123;
function a(){};
console.log(a);//123
GO{
	B:123;
}

function test(){
	var a = b = 123;
	console.log(window.b);//123
	console.log(window.a);//undefined
}
test();
AO{
	a:undefined;
}
function test(){
	console.log(b); //undefined
	if(a)
	{
		var b = 100;
	}
	c = 234;
	console.log(c); //234
}
var a;

test();
a = 10;
console.log(c);//234
1.
function bar(){
	return foo;
	foo = 10;
	function foo(){
		
	}
	var foo = 11;
}
console.log(bar()); //function foo(){}

2.
console.log(bar()); //11
function bar(){
	foo = 10;
	function foo(){
		
	}
	var foo = 11;
	return foo;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值