function Books(title, author, pages, info) {
this.title = title
this.author = author
this.pages = pages
this.info = function() {
return this.title + 'by' + this.author + ',' + this.pages + 'pages' + ',' + 'have read!'
}
}
var books = new Books('Behold a Pale Horse', 'Bill Cooper', 505)
books.info()
答案 0 :(得分:2)
我也可以在这里毫无问题地运行它。我建议进行一些修改,以使代码和印刷文本更具可读性:
function Books(title, author, pages, info) {
this.title = title;
this.author = author;
this.pages = pages;
this.info = () => {
return this.title + ' by ' + this.author + ', ' + this.pages + ' pages' + ',' + ' have read!';
}
}
var books = new Books('Behold a Pale Horse', 'Bill Cooper', 505);
console.log(books.info());
答案 1 :(得分:1)
它正在工作,可能您是说它什么都不打印?
尝试
console.log(books.info())
答案 2 :(得分:1)
尝试:
console.log(books.info())
答案 3 :(得分:1)
您的代码绝对正确。
无法在控制台上打印输出的原因是您没有使用console.log(books.info())
如果您使用Chrome浏览器的控制台,则甚至无需使用console.log()