日期:2014-05-16 浏览次数:20359 次
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();