⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.05 - private methods with closures.js

📁 JS设计模式源代码
💻 JS
字号:
var Book = function(newIsbn, newTitle, newAuthor) { // implements Publication  // Private attributes.  var isbn, title, author;  // Private method.  function checkIsbn(isbn) {    ...   }    // Privileged methods.  this.getIsbn = function() {    return isbn;  };  this.setIsbn = function(newIsbn) {    if(!checkIsbn(newIsbn)) throw new Error('Book: Invalid ISBN.');    isbn = newIsbn;  };  this.getTitle = function() {    return title;  };  this.setTitle = function(newTitle) {    title = newTitle || 'No title specified';  };  this.getAuthor = function() {    return author;  };  this.setAuthor = function(newAuthor) {    author = newAuthor || 'No author specified';  };  // Constructor code.  this.setIsbn(newIsbn);  this.setTitle(newTitle);  this.setAuthor(newAuthor);};// Public, non-privileged methods.Book.prototype = {  display: function() {    ...  }};

⌨️ 快捷键说明

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