最近在看Essential JavaScript Design Patterns For Beginners
原文地址:http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
自己做了点笔记;摘录如下
1、一个设计模式必要的部分:
(1)名称和描述Pattern Name and description
(2)内容提示 context outline——是对用户哪方面需求的响应
(3)问题陈述——正在解决的问题的声明,让别人能够理解模式的意图
(4)解决方案——用户的问题是如何得到解决的,给出一个可理解的列表,包括步骤和想法
(5)设计方案——模式设计的描述,特别要说明关于用户交互的行为描述
(6)实现——模式如何实施的指南
(7)插图——模式中类的可视化描述
(8)例子——用最简单的形式实现的例子
(9)必要条件 ——支持该模式所需的其他模式
(10)关系——这个模式与什么模式类似??它模仿了其他的模式吗?
(11)已知的使用——这个模式已经在被别人使用了吗?如果是,在哪里?是怎样使用的?
(12)讨论——团队和作者对这个模式的想法
2、需要花费一定时间来吸收一些不同的设计模式,并吸取对你有意义的部分 - 这将帮助你实现自己的目标。——学习已有的设计模式(也就是要膜拜大牛~!)
3、构建自己的设计模式的一些提示:
(1)在头脑中确定它的实用性——确保你的模式是解决反复出现的问题而不是临时的解决方案
(2)确保你借鉴了最佳的做法——你所做的设计应该基于那些你从最佳实践中理解的原则
(3)你的设计模式应该对用户透明——设计模式应该是对任何类型的用户完全透明的。
(4)记住!独创性在设计模式中不是最关键的——当在写自己的模式的时候,你不必采用独创的解决方法,也不必担心与其他模式中一些小部件的重合。只要你的模式足够强大,得到了广泛的运用,就有机会被作为是一个适当的模式
(5)了解模式与设计之间的差异——一个设计模式一般来自于被验证了的最佳实践,作为设计师解决问题的模型。模式的作用是给提供设计师指导,使设计师有 更好的设计选择来满足用户的需求。
(6)需要有很多的示例——一个好的模式描述同样需要强大的例子来证明它的成功运用。要显示广泛的应用,理想的例子可以表现出好的设计原则。
4、反模式是一种不好的设计,在JavaScript中有以下几种反模式:
(1)定义大量的全局变量污染命名空间
(2)传递字符串而不是函数,导致setTimeOut()和setInterval都将触发内部使用eval()
(3) Prototyping against the Object object (this is a particularly bad anti-pattern)??对象的反原型?(这是一种恶劣的反模式)
(4)使用内联形式的JavaScript
(5)使用document.write,而document.createElement是比较合适的替代品。document.write已经滥用了多年,有很多缺点,包括如果它在页面加载以后使用,实际上它可以覆盖你的页面,而document.createElement则不会。你可以在http://jsfiddle.net/addyosmani/6T9vX/ 这里看到活生生的例子。另外它 在XHTML中不能使用也是建议使用document.createElement的原因。备注:http://jsfiddle.net/ 这个貌似不错啊。。可以测试很多js。。。
5、几种模式的简单说明
(1)创建型模式:对象创建的基本方法可能会导致在一个项目中增加复杂性,可以通过创建一些模式来解决这个问题,这些创建型模式有:factory(工厂),abstract(抽象),prototype(原型),singleton(单体)和builder(建造者)
(2)结构型模式:此类模式的重点是类和对象的组成结构。结构性的’class’的创建模式使用继承来写接口,’object’模式定义方法创建对象获得新的功能。有:Decorator(装饰者), Façade(外观), Composite(组合), Adapter(适配) and Bridge(桥接)
(3)行为模式:此类模式的焦点在于类中对象之间的通信。它们的目的就是对了更灵活的实现通信的功能。包括:Iterator(迭代), Mediator(调解), Observer(观察) and Visitor(访问).
一、 创建模式
这是其他模式的基础,而且也是很容易理解的。创建模式就是处理应用中创建对象的。在JavaScript中,传统的创建对象的方式(名/值对的集合)如下:
var newObject = new Object();
var newObject = {};
newObject['someValue'] = 'Hello World';
(注:良好的写法是var newObject = {}; 对象直接量的写法。)
分享到:
相关推荐
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 2016年5月2日保存。
With Learning JavaScript Design Patterns, you’ll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to...
True PDF Write reliable code to create powerful applications by mastering advanced JavaScript design patterns
Along the way you’ll discover how to create your own libraries and APIs for even more efficient coding., * Master the basics of object-oriented programming in JavaScript, as they apply to design ...
Design patterns are reusable solutions to commonly occurring problems in software design. They are both exciting and a fascinating topic to explore in any programming language.
Learning JavaScript Design Patterns 英文版,需要的可以看看
Mastering JavaScript Design Patterns
Javascript Design Patterns
Title: Implementing Cloud Design Patterns for AWS Author: Marcus Young Length: 234 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2015-05-15 ISBN-10: 1782177345 ISBN-...
Design Patterns for Embedded Systems in C 英文版 First edition 2011 介绍如何使用设计模式为嵌入式系统创建高效且优化的C语言设计,这些设计方法已经实践证明非常有效。 针对嵌入式系统中发生的问题,本书的...
Create highly efficient design patterns for scalability, redundancy, and high availability in the AWS Cloud About This Book Create highly robust systems using cloud infrastructure Make web ...
javascript设计模式 英文版 pdf
mobi 格式 Implementing Cloud Design Patterns for AWS 01 Implementing Cloud Design Patterns for AWS 01
it contains the advanced concept and technology included the object oriented javascript
Beginning SOLID Principles and Design Patterns for ASP.NET Developers ■Chapter 1: Overview of SOLID Principles and Design Patterns ■Chapter 2: SOLID Principles ■Chapter 3: Creational Patterns: ...
Go Design Patterns for Real-World Projects 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Go: Design Patterns for Real-World Projects What You Will Learn: Install and configure the Go development environment to quickly get started with your first program Use the basic elements of the ...