//利用闭包实现
var Book = (function(){
if(!(this instanceof Book)){
return new Book();
}
var bookNum = 0;
function checkBook(name){}
//创建类
function __book(newId,newName,newPrice){
//私有变量
var name,price;
function checkID(id){}
//特权方法
this.getName = function(){}
this.getPrice = function(){}
this.setName = function(){}
this.setPrice = function(){}
this.getNum = function(){
console.log(bookNum);
}
//公有属性
this.id = newId;
this.copy = function(){};
bookNum++;
if(bookNum>2){
throw(new Error('我们仅出版2本书'));
}
//构造器
this.setPrice(price)
this.setName(name);
}
__book.prototype ={
//静态公有属性
isJsBook:false,
//静态公有方法
display:function(){}
}
return __book;
})()
欢迎关注:http://www.w3schools.top/ 学习您想要的一切IT教程!