注:GO对象会比AO对象先编译;预编译指在执行前会先预编译一次
- GO对象
用于存放全局变量也称为全局作用域<script> var name = '为空' var obg = { name:'逸尘', fun1:function () { console.log(this.name)// => '逸尘' }, fun2:() => { console.log(this.name)// => '为空' } } var fun = obg.fun1// => function () {console.log(this.name)} fun()// => '为空' </script>
- AO对象
将函数里面声明的参数跟变量值都为undefined
函数产生预编译得到AO对象(函数名当做AO对象的属性名)
AO对象里面的参数名跟函数名相同时覆盖参数
函数里面的参数跟函数当做AO对象的属性<script> function fun(a) { console.log(a);// => function a () {} var a = 222; console.log(a);// => 222 function a () {} console.log(a);// => 222 var b = function () {}; console.log(b);// => function () {} function d(){} } fun(1); /** * js预编译 fun AO对象 * fun = { * a:undefined => function a () {} * b:undefined => function () {} * d:undefined => function d(){} * } */ </script>