javascript设计模式(二)--闭包实现

来源:互联网 发布:淘宝白底图片的作用 编辑:程序博客网 时间:2024/05/17 05:54

类的静态变量通过闭包来实现

//var Book = (function(){    //  var bookNum = 0;  //  function checkBook(name){  }  //  return function(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('only sale 100');    this.setName(name);    this.setPrice(price);  }})Book.prototype = {    isJSBook : false,  display : function(){}}


0 0
原创粉丝点击