码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript设计模式(摘译)

时间:2015-11-15 06:19:29      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

说明: 未完成。。。更新中。。。。

一、javascipt设计模式分类

设计模式分类有很多标准,最流行的三种如下

1)  creational  --  主要关注对象创建

Creational design patterns deal directly with object initialization procedures focusing on the creation of situation-specific objects. Without thinking about how objects are created, a level of complexity can be added to the design of an application. Creational design patterns work to solve this problem by adding a layer to the object creation process.

技术分享

2)   structural  --  主要关注对象的组合方法

Structural design patterns are ones that focus on easing the relationship between different components of an application. They help to provide stability by ensuring that if one part of the app changes, the entire thing doesn‘t need to as well.

技术分享

 

3)   behavioral --   主要关注对象间的通信方式

Behavioral design patterns emphasize flexibility through the identification of common communication patterns between various objects.

技术分享

二、日常使用的javascript设计模式

1)The Module Pattern 


2)The Revealing Module Pattern 

 

    var account = function(){
        var balance = 0;

        var deposit = function(money){
            balance + = money;
            console.log("balance after deposti: ",balance);
            sendMsg();
        };

        var withdraw = function(money){
            balance -= money;
            console.log("balance after withdraw",balance);
            sendMsg();
        };

        //私有方法
        var sendMsg = function(){
            console.log("sending message!")
        };

        //公共方法 -- send outside module
        return {
            deposit:deposit,
            withdraw: withdraw
        }
    };

    var a1 = account();
    a1.deposit(100);
    a1.withdraw(20);
    a1.sendMsg();  //could have a alert

 

 

3)The Singleton Pattern 


4)The Observer Pattern 


5)The Mediator Pattern 


6)The Prototype Pattern 


7)The Facade Pattern 


8)The Factory Pattern

 

参看:

  • https://carldanley.com/javascript-design-patterns/#creational-design-patterns

 

Javascript设计模式(摘译)

标签:

原文地址:http://www.cnblogs.com/JoannaQ/p/4966091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!