JSFiddle - React, Tailwind, and code Playground
JavaScript
// 使用闭包
var Book = (function(){
// 静态私有变量
var bookNum = 0;
// 静态私有方法
function checkBook = function(){
}
// 返回构造函数
function _book(newId, newName, newPrice){
// 私有变量
var name,price;
// 私有方法
function checkID(id){
}
// 特权方法
this.getName = function(){}
this.getPrice = function(){}
this.setName = function(){}
this.setPrice = function(){}
// 公有属性
this.id = newId,
// 公有方法
this.copy = function(){}
bookNum ++;
if((bookNum>100)){
throw new Error('我们仅出版100本书')
}
// 构造器
this.setName(name);
this.setPrice(price);
}
_book.prototype = {
isJsBook: true,
display: function(){
}
return _book;
}
});