arguments
类数组对象,代表正在执行的函数的参数。在严格模式下无法使用。
[function.]arguments[n]
含有以下属性
- callee:指向当前函数的引用
- length: 实参个数
- [index]:就是函数的参数值(按参数列表从左到右排列)
caller
是函数对象的属性,指向调用当前函数的函数的引用。
不同于this,不会指向调用方法的对象。
var obj = {
fn: function () {
console.log(arguments.callee.caller);//null
}
};
obj.fn();
<body>
<div onclick="fn0(10)">hello world</div>
</body>
<script>
function fn() {
console.log(arguments);
console.log(fn.arguments);
console.log(fn0.arguments);
console.log(arguments.callee == fn);//true
console.log(fn.arguments.callee == fn);//true
console.log(fn.name);//"fn"
console.log(fn.caller);//fn0
console.log(fn.caller.caller);//f onclick
}
function fn0(num) {
fn(num * 10);
}
</script>
- HTML中的事件调用函数本质上是在事件函数中执行了自定义的函数
<div onclick="fn()">hello world</div>
ƒ onclick(event) {
fn()
}
function fn (){
var e = window.event || arguments.callee.caller.arguments[0];
}
网友评论