var Book = function (newIsbn, newTitle, newAuthor) {
//Priate attributes
var isbn, title, author;
//Private method
function checkIsbn(isbn) {
};
//Privileged methods
this.getIsbn = function () {
return isbn;
};
this.setIsbn = function (newIsbn) {
//if (!checkIsbn(newIsbn)) throw new Error('Book:Invalid ISBN');
isbn = newIsbn || 'no isbn specified';
};
this.getTitle = function () {
return title;
}
this.setTitle = function (newTitle) {
title = newTitle || 'no title specified';
};
this.getAuthor = function () {
return author;
}
this.setAuthor = function (newAuthor) {
author = newAuthor || 'no author specified';
} this.setIsbn(newIsbn);
this.setTitle(newTitle);
this.setAuthor(newAuthor);
};Book.prototype = {
display: function () {
document.write(this.getIsbn + " " + this.getTitle + " " + this.getAuthor + "</br>");
}
};var myBook = new Book("001", "nba2012", "chen");
myBook.display();为什么结果是这个?
//Priate attributes
var isbn, title, author;
//Private method
function checkIsbn(isbn) {
};
//Privileged methods
this.getIsbn = function () {
return isbn;
};
this.setIsbn = function (newIsbn) {
//if (!checkIsbn(newIsbn)) throw new Error('Book:Invalid ISBN');
isbn = newIsbn || 'no isbn specified';
};
this.getTitle = function () {
return title;
}
this.setTitle = function (newTitle) {
title = newTitle || 'no title specified';
};
this.getAuthor = function () {
return author;
}
this.setAuthor = function (newAuthor) {
author = newAuthor || 'no author specified';
} this.setIsbn(newIsbn);
this.setTitle(newTitle);
this.setAuthor(newAuthor);
};Book.prototype = {
display: function () {
document.write(this.getIsbn + " " + this.getTitle + " " + this.getAuthor + "</br>");
}
};var myBook = new Book("001", "nba2012", "chen");
myBook.display();为什么结果是这个?
解决方案 »
- java.lang.ClassNotFoundException: com.lining.servlet.HW2无语了 整了一天了还是没整出来
- [求助]如何在网页中打开EXCEL文件
- 本人想学JavaScript,请热心朋友推荐书目和视频下载地址,俯首感谢!
- 有人用过这个FLASH幻灯不,载进来的图片大小设不定
- 如何实现浏览图片的功能?
- 写了一段定时读写数据库的代码,可是总是第一次成功。。 第二次就不执行了,请各位看看,在线等
- 用div 设置了横向滚动条,如果知道鼠标移动滚动条??谢谢
- 如何知道一个图片链接失败自动使用下一个链接?
- 怎么样让用户每次打开页面的时候都随机显示一个图片广告,要求先算出随机路径,然后再调用一张图片,而不是要读取所有图片然后选择,因为
- 表单中如何将textarea的值中的换行字符替换成空格,在线等!
- 原代码不变的情况下,如何去掉,符号
- jquery实现的幻灯片效果 问题
如果楼主还是觉得奇怪,可以把原型中的display方法稍微修改一下(加三个括号): display: function () {
document.write(this.getIsbn() + " " + this.getTitle() + " " + this.getAuthor() + "</br>");
}