网站建设的知识点有哪些,行政单位门户网站建设方案,vue 网站做中英文切换,天津网站建设外包普通函数的this指向为#xff1a;谁调用它this就指向谁#xff0c;this被不同对象调用是会变的
箭头函数的this指向为#xff1a;声明该箭头函数时#xff0c;外层第一个普通函数的this指向谁就固定为谁#xff0c;不会改变
function foo() {console.log(this)}const ob…普通函数的this指向为谁调用它this就指向谁this被不同对象调用是会变的
箭头函数的this指向为声明该箭头函数时外层第一个普通函数的this指向谁就固定为谁不会改变
function foo() {console.log(this)}const obj {a: 2,foo: function(){console.log(this)}}foo() //this指向为windowobj.foo() //this指向为对象objlet foo2 obj.foofoo2() //this指向为windowlet foo () {console.log(this)}const obj {a: 2,foo: function () {return (){console.log(this)}}}foo() //this指向windowobj.foo()() //this指向对象objlet foo2 obj.foo()foo2() //this指向对象obj箭头函数是匿名函数不能作为构造函数不能使用new
function foo() {console.log(this)}new foo() //windowlet foo2 (){console.log(this)}new foo2() //报错 Uncaught TypeError: foo2 is not a constructor箭头函数不绑定arguments用rest参数...解决
function foo() {console.log(arguments)}foo(1,2,3) //[1,2,3]let foo2 (){console.log(arguments)}foo2(1,2,3) // 报错 Uncaught ReferenceError: arguments is not defined我们可以使用展开符来获取参数
let foo2 (...arguments){console.log(arguments)}foo2(1,2,3) //[1,2,3]
箭头函数使用bind、call、apply无效
var a 1var obj{a:2
}function foo() {console.log(this.a)}foo() //1foo.call(obj) //2输出obj.alet foo2 (){console.log(this.a)}foo2() //1foo2.call(obj) //1仍然输出window.a箭头函数没有原型
var a (){ return 1;}function b(){ return 2;}console.log(a.prototype);//undefinedconsole.log(b.prototype);//object{...}
箭头函数不能当做Generator函数,不能使用yield关键字
箭头函数更简洁适合写一些简单函数