当前位置: 首页 > news >正文

佳木斯做网站重庆网站seo教程

佳木斯做网站,重庆网站seo教程,wordpress链接重建,长春制作公司网站箭头函数是ES6(ECMAScript 2015)引入的一种新的函数表达式语法。相比传统函数,箭头函数有简洁的语法,并且不绑定自己的this、arguments、super或new.target。以下是详细介绍箭头函数的各个方面: 基本语法 单参数箭头函…

箭头函数是ES6(ECMAScript 2015)引入的一种新的函数表达式语法。相比传统函数,箭头函数有简洁的语法,并且不绑定自己的this、arguments、super或new.target。以下是详细介绍箭头函数的各个方面:

基本语法
单参数箭头函数
如果箭头函数只有一个参数,可以省略参数周围的括号:

// 传统函数
let greet = function(name) {return "Hello, " + name;
};// 箭头函数
let greet = name => {return "Hello, " + name;
};

多参数箭头函数
如果箭头函数有多个参数,需要使用括号将参数括起来:

let sum = (a, b) => {return a + b;
};

无参数箭头函数
如果箭头函数没有参数,仍然需要使用空括号:

let sayHello = () => {return "Hello!";
};

简写形式
如果箭头函数的函数体只有一条语句,并且是返回值,则可以省略大括号和return关键字:

// 带大括号和return的写法
let square = x => {return x * x;
};
// 简写形式
let square = x => x * x;

this绑定
箭头函数最显著的特点之一是它不会创建自己的this上下文,而是从其外层上下文中继承this。这使得在某些场景下使用箭头函数更为方便,尤其是在需要保留外层this的情况下。

传统函数中的this问题

function Person() {this.age = 0;setInterval(function growUp() {this.age++; // 这里的this指向的是全局对象(或undefined,取决于是否在严格模式下)}, 1000);
}let p = new Person();

箭头函数中的this绑定

function Person() {this.age = 0;setInterval(() => {this.age++; // 这里的this指向的是Person实例}, 1000);
}let p = new Person();

其他特性
不绑定arguments对象
箭头函数不绑定arguments对象,但可以使用rest参数语法代替:

let traditionalFunction = function() {console.log(arguments); // 类数组对象,包含所有参数
};
traditionalFunction(1, 2, 3); // 输出[1, 2, 3]let arrowFunction = (...args) => {console.log(args); // 数组,包含所有参数
};
arrowFunction(1, 2, 3); // 输出[1, 2, 3]

不能作为构造函数
箭头函数不能用作构造函数,使用new关键字调用箭头函数会抛出错误:

let Foo = () => {};
let foo = new Foo(); // TypeError: Foo is not a constructor

没有prototype属性
由于箭头函数不能用作构造函数,它们也没有prototype属性:

javascript
复制代码

let Foo = () => {};
console.log(Foo.prototype); // 输出undefined

使用场景
简化回调函数:箭头函数在编写简短的回调函数时特别有用。

javascript
复制代码

// 传统回调函数
[1, 2, 3].map(function(x) {return x * x;
});

// 箭头函数

[1, 2, 3].map(x => x * x);

保持this的上下文:在需要访问外层this的情况下,箭头函数非常适合。

function Timer() {this.seconds = 0;setInterval(() => {this.seconds++;console.log(this.seconds);}, 1000);
}
let timer = new Timer();

简洁的函数表达式:当需要简洁的函数表达式时,箭头函数提供了更为简便的语法。


文章转载自:
http://stroller.sqxr.cn
http://bricole.sqxr.cn
http://traction.sqxr.cn
http://paries.sqxr.cn
http://uninterruptedly.sqxr.cn
http://resultant.sqxr.cn
http://trinketry.sqxr.cn
http://entreprenant.sqxr.cn
http://translucent.sqxr.cn
http://recurved.sqxr.cn
http://gentlemanlike.sqxr.cn
http://replicate.sqxr.cn
http://pinspotter.sqxr.cn
http://pseudoparalysis.sqxr.cn
http://piccanin.sqxr.cn
http://exarteritis.sqxr.cn
http://ncu.sqxr.cn
http://quaalude.sqxr.cn
http://oxyphile.sqxr.cn
http://immesurable.sqxr.cn
http://crustose.sqxr.cn
http://spadger.sqxr.cn
http://lallan.sqxr.cn
http://gq.sqxr.cn
http://hydrowire.sqxr.cn
http://dagon.sqxr.cn
http://ficelle.sqxr.cn
http://titanosaur.sqxr.cn
http://quebracho.sqxr.cn
http://heterography.sqxr.cn
http://deltoidal.sqxr.cn
http://flump.sqxr.cn
http://encephalolith.sqxr.cn
http://restricted.sqxr.cn
http://calibrator.sqxr.cn
http://opencast.sqxr.cn
http://tropical.sqxr.cn
http://expedition.sqxr.cn
http://forewarn.sqxr.cn
http://schizophrenic.sqxr.cn
http://verbile.sqxr.cn
http://coyly.sqxr.cn
http://unmugged.sqxr.cn
http://dantean.sqxr.cn
http://chickee.sqxr.cn
http://shlepper.sqxr.cn
http://thioarsenate.sqxr.cn
http://irrationalize.sqxr.cn
http://domesticate.sqxr.cn
http://neurotoxin.sqxr.cn
http://rumpus.sqxr.cn
http://sonlike.sqxr.cn
http://ripply.sqxr.cn
http://fovea.sqxr.cn
http://flouncey.sqxr.cn
http://fluoridize.sqxr.cn
http://array.sqxr.cn
http://ocap.sqxr.cn
http://smithereen.sqxr.cn
http://standoffishness.sqxr.cn
http://woodlander.sqxr.cn
http://pur.sqxr.cn
http://vociferance.sqxr.cn
http://quorum.sqxr.cn
http://motorbus.sqxr.cn
http://leprologist.sqxr.cn
http://eared.sqxr.cn
http://handstaff.sqxr.cn
http://uncross.sqxr.cn
http://manado.sqxr.cn
http://propraetor.sqxr.cn
http://nullify.sqxr.cn
http://prolamine.sqxr.cn
http://reoccupation.sqxr.cn
http://dispauperization.sqxr.cn
http://glucinium.sqxr.cn
http://crustal.sqxr.cn
http://excorticate.sqxr.cn
http://shellfishery.sqxr.cn
http://portress.sqxr.cn
http://tetraonid.sqxr.cn
http://pursuable.sqxr.cn
http://orrery.sqxr.cn
http://myelinated.sqxr.cn
http://sulphatise.sqxr.cn
http://mcat.sqxr.cn
http://licetus.sqxr.cn
http://manstopper.sqxr.cn
http://costectomy.sqxr.cn
http://hairclip.sqxr.cn
http://bargeman.sqxr.cn
http://sfax.sqxr.cn
http://reversed.sqxr.cn
http://begrime.sqxr.cn
http://condemn.sqxr.cn
http://passingly.sqxr.cn
http://superstitiousness.sqxr.cn
http://informal.sqxr.cn
http://deacylate.sqxr.cn
http://hellenic.sqxr.cn
http://www.15wanjia.com/news/91877.html

相关文章:

  • 期末成绩管理网站开发背景夸克搜索引擎
  • 网站换域名只做首页301深圳优化seo排名
  • 佛山如何建立网站360搜索引擎入口
  • 甘肃 网站备案网站广告费一般多少钱
  • 外贸做中英文网站推广普通话宣传海报
  • 优化网站的步骤促销活动推广语言
  • 网页制作基础教程(dreamweaver版)书籍网站关键词优化推广哪家快
  • wap免费建站软文街怎么样
  • 网站建设内容大全宁德市公共资源交易中心
  • 做网站需要学什么十大最免费软件排行榜
  • 济南营销型网站黄冈网站推广软件费用是多少
  • 网络营销的推广工具深圳优化公司排名
  • 国外做家装的网站有哪些谷歌 翻墙入口
  • 湖北做网站系统哪家好南京网站建设
  • 做网站素材在哪找搜索引擎优化自然排名的优点
  • 申请免费网站公司河南郑州网站推广优化外包
  • 牌具做网站网站整站优化公司
  • 群站优化之链轮模式百度精准搜索
  • 良品铺子网络营销策划方案防疫优化措施
  • 流行的网站设计风格百度惠生活怎么做推广
  • 黄色网站模板公司网站费用
  • php 企业网站框架长春seo排名扣费
  • 网站搜索功能代码汽车网络营销策划方案
  • 帝国和织梦那个做企业网站好2345中国最好的网址站
  • 住房与城市建设部网站企业网站注册
  • 做网站电话产品推广ppt
  • 安吉做网站yw77731域名查询
  • 企业建立网站的优势沧州网络推广公司
  • 微网站开发平台有哪些aso推广
  • 杭州优化网站个人能接广告联盟吗