• js 函数的Arguments 对象 学习


    // 严格模式 下
    // 剩余参数、默认参数和解构赋值参数的存在不会改变 arguments对象的行为
    'use strict'
    function func(a) { 
      arguments[0] = 99;   
      console.log(a);// 10
    }
    func(10); // 10
    
    function foo(...args) {
      return args;
    }
    foo(1, 2, 3);  // [1,2,3]
    
    /* --------------------------------*/
    // 非严格模式
    function func(a) { 
      arguments[0] = 99;  // 更新了arguments[0] 同样更新了a 
      console.log(a);// 99
    }
    func(10); // 99
    
    function func(a) { 
      a = 99;              // 更新了a 同样更新了arguments[0] 
      console.log(arguments[0]);
    }
    func(10); // 99
    
    function func(a = 55) { 
      arguments[0] = 99; // 没有更新
      console.log(a);//10
    }
    func(10); // 10
    
    function func(a = 55) { 
      a = 99; // 也没有更新
      console.log(arguments[0]); // 10
    }
    func(10); // 10
    
    function func(a = 55) { 
      console.log(arguments[0]);
    }
    func(); // undefined

    定义连接字符串的函数

    function myConcat(separator) {
      var args = Array.prototype.slice.call(arguments, 1);
      console.log args.join(separator);
    }
    
    //  "red, orange, blue"
    myConcat(", ", "red", "orange", "blue");
  • 相关阅读:
    LNAP安装
    一些不错的资源网站
    转 Android智能手机上捕获数据包
    git命令
    IDEA for Mac 解决控制台乱码问题
    mac上安装port
    Linux
    VIM 技巧 (二)查找与替换
    VIM 技巧 (一)全文统一添加
    Java 查询URL对应IP地址
  • 原文地址:https://www.cnblogs.com/xzma/p/8310842.html
Copyright © 2020-2023  润新知