首页 >> js开发 >> js代码简单了解JavaScript arguement原理及作用
js代码简单了解JavaScript arguement原理及作用
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
问题
问题
var length = 10;
function fn(){
alert(this.length);
}
var obj = {
length: 5,
method: function(fn) {
arguments[0]()
}
}
obj.method(fn);//1
var length = 10;
function fn(){
alert(this.length);
}
var obj = {
length: 5,
method: function(fn) {
arguments[0]()
}
}
obj.method(fn);//1这段代码中的arguments[0]()是第一个参数?带一对小括号是什么意思?理解
理解我们可以先从最后调用obj.method(fn)开始理解。1.obj是对象,method()是obj的方法,fn是method()的参数,fn是函数的名,他引用对应的函数。arguments是JavaScript的一个内置对象。
An Array-like object corresponding to the arguments passed to a function.
The arguments object is a local variable available within all functions; arguments as a property of Function can no longer be used. Description:You can refer to a function‘s arguments within the function by using the arguments object. This object contains an entry for each argument passed to the function, the first entry's index starting at 0.
An Array-like object corresponding to the arguments passed to a function.
The arguments object is a local variable available within all functions; arguments as a property of Function can no longer be used. Description:You can refer to a function‘s arguments within the function by using the arguments object. This object contains an entry for each argument passed to the function, the first entry's index starting at 0.2.arguments是用来取得method(fn)的参数的类数组,在这里也就是fn,即arguments[0]===fn或arguments.0===fn(0就是arguments的一个属性)。所以arguments[0]()就等于fn()。是不是到这里要开始风中凌乱了,this.length究竟是指向那个对象呢? 可以这样理解:
arguments = {
0: fn, //也就是 functon() {alert(this.length)}
1: 第二个参数, //没有
2: 第三个参数, //没有
...,
length: 1 //只有一个参数
}
arguments = {
0: fn, //也就是 functon() {alert(this.length)}
1: 第二个参数, //没有
2: 第三个参数, //没有
...,
length: 1 //只有一个参数
}最后,这个1就是arguments.length,也就是本函数参数的个数。以上就是本文的全部内容,希望对大家的学习有所帮助。
问题
var length = 10;
function fn(){
alert(this.length);
}
var obj = {
length: 5,
method: function(fn) {
arguments[0]()
}
}
obj.method(fn);//1
var length = 10;
function fn(){
alert(this.length);
}
var obj = {
length: 5,
method: function(fn) {
arguments[0]()
}
}
obj.method(fn);//1这段代码中的arguments[0]()是第一个参数?带一对小括号是什么意思?理解
理解我们可以先从最后调用obj.method(fn)开始理解。1.obj是对象,method()是obj的方法,fn是method()的参数,fn是函数的名,他引用对应的函数。arguments是JavaScript的一个内置对象。
An Array-like object corresponding to the arguments passed to a function.
The arguments object is a local variable available within all functions; arguments as a property of Function can no longer be used. Description:You can refer to a function‘s arguments within the function by using the arguments object. This object contains an entry for each argument passed to the function, the first entry's index starting at 0.
An Array-like object corresponding to the arguments passed to a function.
The arguments object is a local variable available within all functions; arguments as a property of Function can no longer be used. Description:You can refer to a function‘s arguments within the function by using the arguments object. This object contains an entry for each argument passed to the function, the first entry's index starting at 0.2.arguments是用来取得method(fn)的参数的类数组,在这里也就是fn,即arguments[0]===fn或arguments.0===fn(0就是arguments的一个属性)。所以arguments[0]()就等于fn()。是不是到这里要开始风中凌乱了,this.length究竟是指向那个对象呢? 可以这样理解:
arguments = {
0: fn, //也就是 functon() {alert(this.length)}
1: 第二个参数, //没有
2: 第三个参数, //没有
...,
length: 1 //只有一个参数
}
arguments = {
0: fn, //也就是 functon() {alert(this.length)}
1: 第二个参数, //没有
2: 第三个参数, //没有
...,
length: 1 //只有一个参数
}最后,这个1就是arguments.length,也就是本函数参数的个数。以上就是本文的全部内容,希望对大家的学习有所帮助。
相关文章:
- jsvue data对象重新赋值无效(未更改)的解决方式js大全
- jsJS前后端实现身份证号验证代码解析js大全
- js在vue中使用防抖函数组件操作js大全
- jsVue中的this.$options.data()和this.$data用法说明js大全
- jsElement Breadcrumb 面包屑的使用方法js大全
- js解决vue动态路由异步加载import组件,加载不到module的问题js大全
- jsAngular利用HTTP POST下载流文件的步骤记录js大全
- js解决vuex数据页面刷新后初始化操作js大全
- jsvue 页面回退mounted函数不执行的解决方案js大全
- jsvue项目使用$router.go(-1)返回时刷新原来的界面操作js大全