how to tell a function arguments length in js

JavaScript函数不对参数值(参数)执行任何检查

https://www.w3schools.com/js/js_function_parameters.asp

// ES5

function functionName(parameter1, parameter2, parameter3) {
// code to be executed
} // ES6 const func = (parameter1, parameter2, parameter3, ...rest) => {
//
}

setTimeout

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Timeouts_and_intervals

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

setTimeout()

setInterval()

setImmediate()

requestAnimationFrame()

https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Code_snippets/Timers


var timeoutID = scope.setTimeout(function[, delay, arg1, arg2, ...]);
var timeoutID = scope.setTimeout(function[, delay]);
var timeoutID = scope.setTimeout(code[, delay]);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now


const start = Date.now();
console.log('starting timer...', start);
// "starting timer..." 1593588039392 const timer = new Date().getTime();
console.log('timer...', timer);
// "timer..." 1593588039392

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

let new_array = arr.map(function callback( currentValue[, index[, array]]) {
// return element for new_array
}[, thisArg])

Functions arguments

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments

convert arguments to a real Array

var args = Array.prototype.slice.call(arguments);
// array literal
var args = [].slice.call(arguments); // ES6 Array.from()
let args = Array.from(arguments); // ES6 spread syntax
let args = [...arguments];

const log = console.log; function func1(a, b, c) {
log(`arguments`, arguments, arguments.length);
log(arguments[0]);
log(arguments[1]);
log(arguments[2]);
} func1(1, 2, 3);

callee & caller

被调用者(接受) & 调用者(发出)

const log = console.log;

function func(a, b, c) {
log(`arguments`, arguments, arguments.length);
log(arguments[0]);
log(arguments[1]);
log(arguments[2]);
} func(1,2,3) ;

const log = console.log; const obj = {
name: 'abc',
getName: () => log(this.name),
}; obj.getName();
const log = console.log;

const obj = {
name: 'abc',
getName: function() {
log(`arguments`, arguments, arguments.length);
log(this.name);
},
}; obj.getName();

'caller', 'callee', and 'arguments'

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or

the arguments objects for calls to them at Function.invokeGetter (:1:142)

demos

let cb = v => console.log(v || `default value`)
// cb = v => console.log(arguments.length, v || `default value`) function func(v) {
console.log(arguments.length, v || `default value`)
}

ES6 arrow function 不存在 arguments 对象


xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


how to tell a function arguments length in js的更多相关文章

  1. JavaScript Function arguments.callee caller length return

    一.Function 函数是对象,函数名是指针. 函数名实际上是一个指向函数对象的指针. 使用不带圆括号的函数名是访问函数指针,并非调用函数. 函数的名字仅仅是一个包含指针的变量而已.即使在不同的环境 ...

  2. arguments .length .callee caller

    如果有一个函数像下面这样: function fn(){ } 那么fn这个函数下面就有一个arguments属性(你在逗我么,后面又说对象),该属性是个对象(typeof一下就知道了),然后它下面也有 ...

  3. js小记 function 的 length 属性

    原文:js小记 function 的 length 属性 [1,2,3]., ,这个略懂js的都知道. 但是  eval.length,RegExp.length,"".toStr ...

  4. JavaScript Function.arguments 属性详解

    语法 [functionObject.]arguments arguments属性是正在执行的函数的内置属性,返回该函数的arguments对象.arguments对象包含了调用该函数时所传入的实际参 ...

  5. JS Function Arguments

    Function arguments在ECMAScript中的行为并不像其他大多数语言中的函数参数. 在ECMAScript中,function 并不关心有多少个参数传入函数中,也不关心传入参数的数据 ...

  6. arguments.length

    本文地址:http://www.cnblogs.com/veinyin/p/7607083.html  arguments.length是实参的个数,与形参个数无关.

  7. [Javascript] Required function arguments in Javascript

    In Javascript, all function arguments are optional by default. That means if you ever forget to pass ...

  8. js function arguments types

    js function arguments types https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functi ...

  9. ES6教程-字符串,函数的参数,了解函数的arguments对象,js面向对象,设计模式-单例模式,解构赋值

    前言 主要讲解了ES6对字符串的拓展,包括includes,startsWith和endsWith,另外增加了字符串模板. Start includes()是否包含 startsWith()以什么开头 ...

随机推荐

  1. Uber如何解决2000多个微服务带来的复杂性问题?

    Uber如何解决2000多个微服务带来的复杂性问题? Adam Gluck 架构头条 2020-10-29 https://mp.weixin.qq.com/s/N7fVDZVm8uC9wVvd9DQ ...

  2. 亿级用户下的新浪微博平台架构 前端机(提供 API 接口服务),队列机(处理上行业务逻辑,主要是数据写入),存储(mc、mysql、mcq、redis 、HBase等)

    https://mp.weixin.qq.com/s/f319mm6QsetwxntvSXpKxg 亿级用户下的新浪微博平台架构 炼数成金前沿推荐 2014-12-04 序言 新浪微博在2014年3月 ...

  3. int ping = 11; 限流 客户端验证与服务端是连接的

    int ping = 11; ZooKeeper Programmer's Guide https://zookeeper.apache.org/doc/r3.1.2/zookeeperProgram ...

  4. Flash 终将谢幕:微软将于年底( 2020 年 )停止对 Flash 的支持

    近日,微软宣布将于今年 12 月终止对 Adobe Flash Player 的支持,届时,微软旗下所有浏览器都将无法使用 Flash,Adobe 也不会在今年 12 月后发布安全更新.早在 2017 ...

  5. C语言中使用类似awk的功能

    awk实在是太强大了, 非常复杂的任务,几行代码就可以解决, awk经常需要用到, 但是在c语言里面, 调用system不太优雅, 能不能直接在c语言中直接调用呢,简单实现了一些功能, 但大多数情况, ...

  6. 十二:SpringBoot-基于Cache注解模式,管理Redis缓存

    SpringBoot-基于Cache注解模式,管理Redis缓存 1.Cache缓存简介 2.核心API说明 3.SpringBoot整合Cache 3.1 核心依赖 3.2 Cache缓存配置 3. ...

  7. Javascript关键字,条件语句,函数及函数相关知识

    关键字 条件语句 作用域 回调 关键字 根据规定,关键字是保留的,不能用作变量名或函数名. 下面是一些ECMAScript关键字的完整列表. break ,case,catch,continue,de ...

  8. UML——交互图(序列图+协作图)

    交互图(interaction diagram):是协作图=通信图UML2.0以后的叫法=合作图=(Collaboration /Communication Diagram)以及序列图=顺序图=时序图 ...

  9. docker启动脚本

    #!/bin/bash # 定义环境变量 export LANG="en_US.UTF-8" #统一格式化打印输出信息 printMsg(){ echo "$(date ...

  10. var_dump和var_export区别

    1.var_dump() :获取结构化的数据,按照数组的层级输出 2.var_export() :获取结构化的数据,返回有效的php代码,保留结构化形式的存储数据,数据类型为字符串. 例如: < ...