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();为什么结果是这个?
解决方案 »
- js 一些问题
- document.form1.submit()前加上一个if判断为什么不行?(在线等)
- 看见一个别人的股票网站的html代码上有一段javascript代码,我要调试这个代码要用什么调试器呀?
- 求助关于事件触发后获取触发源ID的问题
- 怎样给select的同一个option设定多个value值?
- ie打印问题?如何设置纸张的大小,我是指自定义大小...
- 我将提供一个简短的,快餐式的关于JavaScript的入门读物给大家
- [紧急求助]一个简单的函数调用返回值的问题,请各位看看问题在哪里?[我在线等候]
- 关于Dreamweaver中‘表单’控件中的内容提交到邮箱的问题
- 如何控制鼠标放在连接上时IE的状态条?
- 原代码不变的情况下,如何去掉,符号
- jquery实现的幻灯片效果 问题
如果楼主还是觉得奇怪,可以把原型中的display方法稍微修改一下(加三个括号): display: function () {
document.write(this.getIsbn() + " " + this.getTitle() + " " + this.getAuthor() + "</br>");
}