Blogger Information
Blog 22
fans 0
comment 0
visits 11445
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用函数类型和数据类型
没耐心的渔翁
Original
802 people have browsed it

常用几种函数类型

1.命名函数

function sum (a,b){ return a + b; } console.log(sum(5,5));

2.匿名函数(可以分成三种)

  • 第一种,将匿名函数当成一个值赋函数
    let ss = function (username){ return 'hello' + username; } console.log(ss('欧阳老师'));
  • 第二种 将声明和调用合二为一。立即调用,IIFE
    let dd= ( function (username){ return 'hello' + username; }); console.log(dd('贱人')); console.log(function (username){ return 'hello' + username; })('朱老师') );
  • 第三种 .胖箭头函数
    转化方法
    1.去掉 function
    2.在参数列表和大括号之间加上(=>)
    //将命名函数转为匿名函数
    let abb =function (a,b){ console.log(a + b); } //使用箭头来简化匿名函数 abb = (a,b) =>{ console.log(a + b); } abb(1,2);

    数据类型

    1.原始类型

  • umber
    console.log(typeof 100);

    • string
      console.log(typeof ('hello' +100) );

    • boolean
      console.log(typeof true);

    • undefined
      console.log(undefined)

    • null
      console.log(null)

    2.引用类型

    • arr
      const arr =[1,2,35,8]; console.log(arr[2]);

    • object
      const obj={id:1,username:'pit',email:'lalal@qq.com'}; //obj 对象特有的访问方式 console.log(obj.email); //1.数组访问方式 console.log(obj['username'])

    • function
      function f2(){ //let a是私有变量 let a = 1; return function (){ //子元素中的a此时是继承父元素的 return a++; }; } //打印第一个函数 //console.log(f2()); const f = f2(); console. log(f());

      函数就是对象,对象就可以添加属性和方法

      `let f3 = function() {}; f3.myemail = '1023621130@qq.com'; f3.username='lllll'; console.log(f3); f3.getUser=function(){ console.log(this.username); } f3.getUser();

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