3.03 - private methods with underscores.js

来自「JS设计模式源代码」· JavaScript 代码 · 共 37 行

JS
37
字号
var Book = function(isbn, title, author) { // implements Publication  this.setIsbn(isbn);  this.setTitle(title);  this.setAuthor(author);}Book.prototype = {  _checkIsbn: function(isbn) {    ...  },  getIsbn: function() {    return this._isbn;  },  setIsbn: function(isbn) {    if(!this._checkIsbn(isbn)) throw new Error('Book: Invalid ISBN.');    this._isbn = isbn;  },  getTitle: function() {    return this._title;  },  setTitle: function(title) {    this._title = title || 'No title specified';  },  getAuthor: function() {    return this._author;  },  setAuthor: function(author) {    this._author = author || 'No author specified';  },    display: function() {    ...  }};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?