//执行环境中var 声明提升
void function(){
console.log(baba);
var baba=100;
}()
VM402:3 undefined
undefined
会输出undefined 而不是报错,说明baba已经有了声明,未有初始值
//hoist 函数声明提升
add(1,2)//3
function add(n1,n2){return n1+n2};
//没有函数提升
hei(2,3);
var hei=(n1,n2)=>{return n1+n2}
VM586:1 Uncaught TypeError: hei is not a function
at <anonymous>:1:1
箭头函数只是一个没有内置改变this功能,没有arguments类数组对象,没有函数提升,的纯函数
a.__proto__.arguments
VM3002:1 Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at <anonymous>:1:13
箭头函数就是在"use strict"模式下的函数,所以 caller callee arguments都不能访问,this也不会改变,所以不能用作构造函数,es6中有自己的构造函数和类声明方法
var ds=(lala,liu)=>{this.lala=lala,this.liu=liu};
var hei=new ds("ds","ds")
VM853:2 Uncaught TypeError: ds is not a constructor
at <anonymous>:2:9
this 指向永远windiw||undefined 没有构造函数的功能
用class person(){}代替
Function.prototype.__proto__
{constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}
Object.prototype
{constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}
Function.prototype
ƒ () { [native code] }
this
引用的是函数据以执行的环境对象——或者也可以说是 this 值(当在网页的全局作用域中调用函数时,
this 对象引用的就是 window)。
Object String Array Number Boolean RegExp 都是引用类型,也是构造函数,函数的两个外部属性 length prototype
caller (调用当前函数的函数的引用,
如果是在全局作用域中调用当前函数,它的值为 null) 也是个函数