how to tell a function arguments length in js
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的更多相关文章
- JavaScript Function arguments.callee caller length return
一.Function 函数是对象,函数名是指针. 函数名实际上是一个指向函数对象的指针. 使用不带圆括号的函数名是访问函数指针,并非调用函数. 函数的名字仅仅是一个包含指针的变量而已.即使在不同的环境 ...
- arguments .length .callee caller
如果有一个函数像下面这样: function fn(){ } 那么fn这个函数下面就有一个arguments属性(你在逗我么,后面又说对象),该属性是个对象(typeof一下就知道了),然后它下面也有 ...
- js小记 function 的 length 属性
原文:js小记 function 的 length 属性 [1,2,3]., ,这个略懂js的都知道. 但是 eval.length,RegExp.length,"".toStr ...
- JavaScript Function.arguments 属性详解
语法 [functionObject.]arguments arguments属性是正在执行的函数的内置属性,返回该函数的arguments对象.arguments对象包含了调用该函数时所传入的实际参 ...
- JS Function Arguments
Function arguments在ECMAScript中的行为并不像其他大多数语言中的函数参数. 在ECMAScript中,function 并不关心有多少个参数传入函数中,也不关心传入参数的数据 ...
- arguments.length
本文地址:http://www.cnblogs.com/veinyin/p/7607083.html arguments.length是实参的个数,与形参个数无关.
- [Javascript] Required function arguments in Javascript
In Javascript, all function arguments are optional by default. That means if you ever forget to pass ...
- js function arguments types
js function arguments types https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functi ...
- ES6教程-字符串,函数的参数,了解函数的arguments对象,js面向对象,设计模式-单例模式,解构赋值
前言 主要讲解了ES6对字符串的拓展,包括includes,startsWith和endsWith,另外增加了字符串模板. Start includes()是否包含 startsWith()以什么开头 ...
随机推荐
- Elasticsearch--ES-Head--docker版安装
1.0ElasticSearch安装 # 拉取ES镜像docker pull elasticsearch:6.5.0 # 设置vm.max_map_count大小sysctl -w vm.max_ma ...
- 【Soul网关探秘】http数据同步-Web端处理变更通知
个人知识库 引言 上一篇,梳理http 数据同步策略的变更通知机制,本篇开始探究配置变更通知到达后, soul-web 端的处理响应. 不同数据变更的通知机制应当是一致的,故本篇以 selector ...
- LibreOJ #10047
应同机房某大佬的要求来写这篇题解 Description 给定一个字符串 \(S\) 和一个数 \(K\),要求求出 \(S\) 的所有形似 \(A+B+A\) 的子串数量,其中 \(\mid A\m ...
- mysql数据恢复:.frm和.ibd,恢复表结构和数据
mysql数据恢复:.frm和.ibd,恢复表结构和数据 一.恢复表结构 二.恢复表数据 相关内容原文地址: CSDN:她说巷尾的樱花开了:mysql根据.frm和.ibd文件恢复表结构和数据 博客园 ...
- Cisco动态路由(rip)
接Cisco静态路由,讨论一下Cisco动态路由. 实验环境布置 命令布置动态路由 Router0: Router>enable Router#configure terminal Router ...
- 【疑】checkpoint防火墙双链路负载均衡无法配置权重问题
现状: 按照上一篇checkpoint疑难中描述,已完成双机+双链路冗余配置 故障现象: 外网出口为200M电信+200M联通,CP上负载权重设置如下 但是在实际使用中发现电信出口流量远大于联通. 调 ...
- Jenkins(4)docker容器内部修改jenkins容器时间
前言 用docker搭建的Jenkins环境时间显示和我们本地时间相差8个小时,需修改容器内部的系统时间 查看时间 查看系统时间 date-R 进入docker容器内部,查看容器时间 docker e ...
- [CF套题] CF-1163
CF-1163 传送门 # Penalty A B1 B2 C1 C2 D E F 3 (483) 464 +0 0:06 +1 01:13 +3 01:12 + 01:57 + 01:56 A 第一 ...
- Codeforces 1355 D. Game With Array
传送门:D - Game With Array 题意:让你构造一个长度为n的序列,并且n个数的和为S,问能不能找到一个1~n的数k,使得数组里找不出一个子序列的和为k或者n-k: 题解:最简单的想法肯 ...
- 【noi 2.6_7627】鸡蛋的硬度(DP)
题意:其中n表示楼的高度,m表示你现在拥有的鸡蛋个数. 解法:f[i][j]表示 i 层楼有 j 个鸡蛋时,至少要扔多少次.3重循环,k为测试的楼层,分这时扔下去的鸡蛋碎和不碎的情况.要注意初始化. ...