Blogger Information
Blog 42
fans 0
comment 0
visits 15746
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0721函数参数类型模板字面量与模板函数闭包
小言
Original
460 people have browsed it

函数参数类型与返回值方法

1.参数,包括以下内容 :一一对应,如果参数不足时,可以给入一个默认值,返回默认值。当内容过多时,可以用… 来进行声明 ,压入数组或者展开

  1. function hello1(name,...users){
  2. // return 'hello,' + username;
  3. console.log(name);
  4. return users;
  5. }
  6. console.log(hello1('测试' , '没说' , '不说'));

  1. function hello2(...users){
  2. // return 'hello,' + username;
  3. console.log(name);
  4. return users;
  5. }
  6. const arr = ['测试1' , '没说2' , '不说3'];
  7. console.log(hello2(...arr));

模板字面量与模板函数

1.模板字面量就是可以使插值当成表达式的字符串来进行表示

  1. let username = '12测试';
  2. console.log(`hello ${username}`);

2.模板函数 就是可以把模板字面量来当成参数来使用的函数

  1. function total (strings, ...args){
  2. console.log(strings);
  3. console.log(args);
  4. }
  5. let name = '手机';
  6. let num = 10;
  7. let price = 500;
  8. total `名称:${name},数量:${num},单价:${price}`;

闭包

1.闭包的形成条件,需要有父子函数,子函数中调用父函数的变量

  1. fn = function(a){
  2. return function(b){
  3. return function (c){
  4. return function(d) {
  5. return a + b + c + d;
  6. };
  7. };
  8. };
  9. };

2.纯函数

纯函数就是可以将外部的自由变量,通过传参的方式到函数中,不用直接在函数中来使用

  1. let x = 0.5;
  2. function getPrices(price,x){
  3. return price * x;
  4. }
  5. console.log(getPrices(1000,x));

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post