读《JavaScript设计模式》笔记之属性与方法的封装

来源:互联网 发布:保罗皮尔斯数据 编辑:程序博客网 时间:2024/06/04 19:06
//私有属性与私有方法,特权方法,对象公有属性和对象公有方法,构造器var Book = function (id, name, price) {    //私有属性    var num=1;    //私有方法    function checkId() {};    //特权方法()    this.getName= function () {};    this.getPrice= function () {};    this.setName= function () {};    this.setPrice= function () {};    //对象公有属性    this.id=id;    //对象公有方法    this.copy=function () {};    //构造器    this.setName(name);    this.setPrice(price);};//类静态公有属性(对象不能访问)Book.isChinese=true;//类静态公有方法(对象不能访问)Book.resetTime=function () {    console.log('new time');};Book.prototype={    //公有属性    isJSBook: false,    //公有方法    display: function () {        console.log('display');    }};



阅读全文
1 0
原创粉丝点击