函数参数默认值

前言

6aae844a4f776f2a1ed874df9e51088b.png

我是歌谣 最好的种树是十年前 其次是现在 今天继续给大家带来的是this指向的讲解

环境配置

ab81bd88118d3054d002f22bc21fedf1.png

npm init -y
yarn add vite -D

 修改page.json配置端口

669cac9bffd5e0de22d79f91dc559737.png

{
  "name": "demo1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "vite --port 3002"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "vite": "^4.4.9"
  }
}

 案例1

acc3ea9a5c1a5e6731bd36fcaa75640c.png

function test(a=1,b){
    console.log(a)
    console.log(b)
}
test(undefined,2)

 运行结果

d54a329deb12d7c8c82dd32ece038b39.png

5345759f5b776a0bf90a5a5403e2e59c.png

 案例2

8a9ca5eb40ec27de0922fea348c5e012.png

function test(a,b){
    var a=arguments[0]||1;
    var b=arguments[1]||2;
    console.log(a)
    console.log(b)
}
test(undefined,2)

 运行结果

890893e375be83ee4772a3841877eef8.png

114a707216c8db9ea90ac43e03cee2c5.png

案例3

14918892cb3ed4ea3b362e0d8451a667.png

function test(a, b) {
    var a, b;
    if (typeof (arguments[0] !== 'undefind')) {
        a = arguments[0]
    } else {
        a = 1
    }
    if (typeof (arguments[1] !== 'undefind')) {
        b = arguments[1]
    } else {
        b = 2
    }
    console.log(a)
    console.log(b)
}
test(2, 3)

 运行结果

388877a5768a5c7440bf248b1eac6f19.png

697fd50fc3e1678e167e5da06955a92d.png

点击上方蓝字关注我们

787e405eea0951f25415ae43322aec20.png

下方查看历史文章

637836f5794387a9192300e80f0e00f4.png

函数基础

caller和caller

this指向

对象属性的遍历

Pinia使用案例

posted @ 2023-10-30 09:41  前端导师歌谣  阅读(19)  评论(0)    收藏  举报  来源