本帖最后由 hechengjin 于 2015-10-22 13:15 编辑  
 
JavaScript设计模式共有两部分。第一部分给出了实现具体设计模式所需要的面向对象特性的基础知识,主要包括接口、封装和信息隐藏、继承、单体模式等内容。第二部分则专注于各种具体的设计模式及其在JavaScript语言中的应用,主要介绍了工厂模式、桥接模式、组合模式、门面模式等几种常见的模式。为了让每一章中的示例都尽可能地贴近实际应用,书中同时列举了一些JavaScript 程序员最常见的任务,然后运用设计模式使其解决方案变得更模块化、更高效并且更易维护,其中较为理论化的例子则用于阐明某些要点。 
 
 
avaScript设计模式 中文清晰扫描版PDF 百度网盘下载:http://pan.baidu.com/s/1mg8a9rM ------------------------------------------分割线------------------------------------------ FTP地址:ftp://ftp1.linuxidc.com 用户名:ftp1.linuxidc.com 密码:www.linuxidc.com 在 2015年LinuxIDC.com\9月\JavaScript设计模式 中文清晰扫描版PDF 下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm ------------------------------------------分割线------------------------------------------ 本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-09/122725.htm  
  
 第四章 继承 类式继承 function Person(name){   this.name = name; }  
 Person.prototype.getName = function() {   return this.name; }  
 var reader = new Person('John Smith'); reader.getName();  
  
 function Author(name, books){   Person.call(this, name); //Call the superclass's constructor in the scope of this.   this.books = books; //Add an attribute to Author. }  
 Author.prototype = new Person();  //Set up the prototype chain. Author.prototype.constructor = Author; //Set the constructor attribute to Author. Person.prototype.getBooks = function() {  //Add a method to Author.   return this.books; }  
 var author = new Author('Ross Harmes', ['JavaScript Design Patterns']); author.getName(); author.getBooks();  
 建议下面写法 function Contacts() 
{ 
   ContactsStorageBase.call(this);  
} 
 
 
Contacts.prototype = { 
  __proto__: ContactsStorageBase.prototype, 
 
 
//CURD 
  create: function(contactInfo) { 
    return this.db.contacts.add(contactInfo); 
  }, 
 
 
 read: function() { 
         return this.db.contacts.where("id").notEqual(0).toArray(); 
 } 
 
 
 
} 
 
 
  
 原型式继承  
 
  
 |