简体   繁体   English

为什么参数对象未在控制台中显示其方法

[英]why arguments object is not showing it's method in console

Take a look at this code: 看一下这段代码:

var args;
function foo(){
  args = arguments;
}

foo();

console.log(args); // []
args.callee(); // foo

how come I'm not able to see any property or method of arguments object in console yet able to call callee method ? 为什么在控制台中看不到参数对象的任何属性或方法,却能够调用被调用方方法呢?

You are not passing foo any arguments. 您没有向foo传递任何参数。 Also, The callee property is "non-enumerable". 同样, callee属性是“不可枚举的”。

Disclaimer: this assumes you're using the Chrome or Firebug consoles, there is no standard, so custom consoles might do funky things. 免责声明:这是假设您使用的是Chrome或Firebug控制台,没有标准配置,因此自定义控制台可能会做一些时髦的事情。

Because you used console.log which displays array-like* objects differently from "plain" objects. 因为您使用了console.log ,它显示的类似于数组的对象与“普通”对象不同。 If you want to see the properties on the object, use console.dir . 如果要查看对象的属性,请使用console.dir

* to be array-like the object has to have a length property and splice function, or a number of other niche conditions. *要像数组一样,对象必须具有length属性和splice函数,或者具有许多其他特殊条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么控制台不使用输入对象的`toString`方法? - Why the console doesn't use entered object's `toString` method? 当有 object 时,为什么控制台中显示“Null 不是对象”? - Why is 'Null is not an Object' showing in console when there is an object? Ramda function 用 arguments 调用对象的方法? - Ramda function for calling an object's method with arguments? Javascript Object 方法值未与 object 的 console.log 一起显示 - Javascript Object method value not showing with console.log of the object 用不同的 arguments 在另一个类的属性中绑定对象的方法 - Binding an object's method in another class's property with different arguments Node 的控制台没有显示所有对象属性......这是预期的行为吗? - Node's console is not showing all the object properties ... is this expected behavior? 为什么在chrom的console-> application-> localStorage中显示null - Why null is showing in chrom's console->application->localStorage Chrome开发人员工具控制台显示了褪色的Javascript对象属性,为什么? - Chrome developer tools console showing faded Javascript object property, why? 使用console.log时,为什么Javascript中的参数返回[object Arguments]? - Why does arguments in Javascript return [object Arguments] when using console.log? 为什么我不能在函数的参数上调用数组方法? - Why can't I call an array method on a function's arguments?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM