Javascript 创建对象实例时不显示控制台日志记录

Javascript 创建对象实例时不显示控制台日志记录,javascript,Javascript,代码片段1: <script> function Person(lastName, firstName){ this.lastName = lastName; this.firstName = firstName; } var DnnyGdmn = new Person("Goodman","Danny"); var DvdFlngn = new Person("Flanagan","David"); function Book(title, pages, pric

代码片段1:

<script>
function Person(lastName, firstName){ 
  this.lastName = lastName; 
  this.firstName = firstName; 
}
var DnnyGdmn = new Person("Goodman","Danny"); 
var DvdFlngn = new Person("Flanagan","David"); 
function Book(title, pages, price){ 
  this.title = title; 
  this.pages = pages; 
  this.price = price; 
  this.authors = new Array(arguments.length-3);
  console.log(arguments);
  for(i = 0; i < arguments.length - 3; i++){ 
    this.authors[i] = arguments[i + 3]; 
  } 
}
var JavaNut = new Book("Java Foundation Classes in a Nutshell", 731, 29.95, DvdFlngn); 
var JSTDR = new Book("Javascript: The Definitive Guide (3rd  Edition)", 776, 39.95, DvdFlngn); 
</script>
代码段2:

<script>
function Person(lastName, firstName){ 
  this.lastName = lastName; 
  this.firstName = firstName; 
}
var DnnyGdmn = new Person("Goodman","Danny"); 
var DvdFlngn = new Person("Flanagan","David"); 
</script>
在Firefox firebug->console->all中,它没有显示任何内容

问题:

这两个代码段都做了相同的事情,创建了某个对象的实例,但是为什么1要向console写入某些内容,而代码2却没有呢?

在代码1中,您有以下内容:

console.log(arguments);
这可以在这里找到:

  ...
  this.pages = pages;
  this.price = price;

  this.authors = new Array(arguments.length-3); console.log(arguments);

  for(i=0;i<arguments.length-3;i++){
    this.authors[i] = arguments[i+3];
  }
  ...
此代码将参数值写入控制台。由于代码2中不存在代码,因此它不会在控制台中输出任何内容。

在第二个示例中,您在哪里使用console.log?
  ...
  this.pages = pages;
  this.price = price;

  this.authors = new Array(arguments.length-3); console.log(arguments);

  for(i=0;i<arguments.length-3;i++){
    this.authors[i] = arguments[i+3];
  }
  ...