arguments用法(parameter和argument有何区别)
本文目录
- parameter和argument有何区别
- java script
- 求教js函数传参,使用arguments计算参数值
- this.method.apply(this,arguments) 这样的用法是什么意思
parameter和argument有何区别
******************argument n.(名词) (1) Mathematics 【数学】 (2) A constant in an equation that varies in other equations of the same general form, especially such a constant in the equation of a curve or surface that can be varied to represent a family of curves or surfaces. 参数,参量:在相同一般类型的等式中取值变化的等式中的常数或常量,尤其是曲线方程和平面方程中能代表一类曲线或平面的常量 (3) One of a set of independent variables that express the coordinates of a point. 变量,参数:一组代表与之对应的点的独立变量之一 (4) One of a set of measurable factors, such as temperature and pressure, that define a system and determine its behavior and are varied in an experiment. 要素,测量元素之一:一组可测量的确定某一系统并决定该系统的状况且在实验中是变化的因素之一,例如温度和压力 (5) Usage Problem A factor that restricts what is possible or what results: 【用法疑难】 限制因素:限定可能性和结果的因素: “all the parameters of shelter—where people will live, what mode of housing they will choose, and how they will pay for it”(New York) “住宿的所有限制因素——人们住在哪里、他们将选择什么样的住房式样以及他们如何付房钱”(纽约) (6) A factor that determines a range of variations; a boundary: 决定变数范围的要素,范围,界限:决定变化范围的因素;限度: an experimental school that keeps expanding the parameters of its curriculum. 一所不断扩展课程范围的实验学校 (7) Statistics A quantity, such as a mean, that is calculated from data and describes a population. 【统计学】 母数:一种如平均数等从数据中计算出来的用来描述总体的数值 (8) Usage Problem A distinguishing characteristic or feature. 【用法疑难】 特色,特征:区别于其它事物的特点或性质
java script
arguments在 JavaScript 中,在一个 function 内部可以使用 arguments 对象。该对象中包含了 function 被调用时的实际参数的值。 arguments 对象虽然在功能上有些类似数组(Array),但是它不是数组。 arguments 对象与数组的类似体现在它有一个 length 属性,同时实际参数的值可以通过 操作符来获取。但是 arguments 对象并没有数组可以使用的 push、pop、splice 等 function 。其原因是 arguments 对象的 prototype 指向的是 Object.prototype 而不是 Array.prototype 。使用 arguments 模拟重载Java 和 C++ 语言都支持方法重载(overloading),即允许出现名称相同但是形式参数不同的方法;而 JavaScript 并不支持这种方式的重载。因为 JavaScript 中的 function 对象也是以属性的形式出现的,在一个对象中增加与已有 function 同名的新 function 时,旧的 function 对象会被覆盖。不过可以通过使用 arguments 来模拟重载,其实现机制是通过判断 arguments 中实际参数的个数和类型来执行不同的逻辑。如代码清单 2中所示。清单 2. 使用 arguments 模拟重载示例function sayHello() { switch (arguments.length) { case 0: return “Hello“; case 1: return “Hello, “ + arguments; case 2: return (arguments == “cn“ ? “ 你好,“ : “Hello, “) + arguments; }; } sayHello(); // 结果是 “Hello“ sayHello(“Alex“); // 结果是 “Hello, Alex“ sayHello(“Alex“, “cn“); // 结果是 “ 你好,Alex“arguments.calleecallee 是 arguments 对象的一个属性,其值是当前正在执行的 function 对象。它的作用是使得匿名 function 可以被递归调用。下面以一段计算斐波那契序列(Fibonacci sequence)中第 N 个数的值的代码来演示 arguments.callee 的使用,见代码清单 3。清单 3. arguments.callee 示例function fibonacci(num) { return (function(num) { if (typeof num !== “number“) return -1; num = parseInt(num); if (num 《 1) return -1; if (num == 1 || num == 2) return 1; return arguments.callee(num - 1) + arguments.callee(num - 2); })(num); } fibonacci(100);
求教js函数传参,使用arguments计算参数值
function sum(){
var temp = arguments;
if(arguments.length 》= 4){
for(var i = 1;i 《 arguments.length-1;i++){
switch(arguments){
case ’+’:
temp += arguments;
break;
case ’-’:
temp -= arguments;
break;
case ’*’:
temp *= arguments;
break;
case ’/’:
temp /= arguments;
break;
case ’%’:
temp %= arguments;
break;
case ’^’:
temp ^= arguments;
break;
default:
return;
break;
}
}
return temp;
}
}
console.log(sum(1,1,1,1,’+’));
运行结果如下图:
this.method.apply(this,arguments) 这样的用法是什么意思
this.method.apply(this, arguments) 传参 this ,只是一个引用对象,可以是apply的调用对象,也可以是 this.method.apply(new Object(), arguments),说明调用apply的 this 中的 this 为 new Object(),这就说明了,当 var a = new Object(); this.method.apply(a, arguments); 时,就相当于 a.method(arguments) ,而不再是 this.method(arguments)简单一句,这是一个借用别人方法来调用,自己就不用写这个方法了
更多文章:
udp协议和tcp协议的区别(如何通俗地解释TCP和UDP协议和HTTP、FTP、SMTP等协议之间的区别)
2025年2月28日 04:30
downloading文件怎么打开(downloading文件用什么软件打开)
2025年2月10日 20:30
html简单的个人主页(谁给我做一个简单的HTML CSS的静态个人主页,朋友要的糊弄老师的)
2025年2月11日 07:00
destruction翻译(the road to destruction课文翻译)
2025年3月18日 07:00
exchange服务器(微软为何决定推迟Exchange Server 2010的扩展支持截止日期)
2025年3月18日 09:10
preparedstatement(PreparedStatement 是什么)
2025年2月22日 16:30
html链接css代码怎么写(怎么将css文件链接到html)
2025年3月30日 21:30
安卓应用商店 apk(安卓在应用商店里面apk的图标设计尺寸是什么圆角多少)
2025年4月7日 17:50
carpe diem(死亡诗社中怎样理解carpe diem)
2025年2月12日 22:00
spring boot定时任务(springboot中怎么实现定时任务)
2025年3月13日 23:50