说明: 未完成。。。更新中。。。。
一、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.
创建型设计模式直接处理对象的初始化程序,重点关注创建基于特定场景的对象。它不关注如何创建对象,其复杂性的层次直接加入到应用程序的设计中。创建型设计模式通过在对象创建过程上加上一层来解决问题。
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设计模式
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
var PersonSingleton =(function(){ var instantiated; function init(){ function myOtherMethod() { alert( 'my other method' ); } return{ name: 'Anonymous', work: function(){ console.log(this.name + "is working"); }, someOtherMethod: myOtherMethod } } return{ //handles the prevention of additional instantiations getInstance: function(){ if(!instantiated){ instantiated = init(); } return instantiated; } } })(); var p1 = PersonSingleton.getInstance(); p1.work(); //return Anonymouse var p2 = PersonSingleton.getInstance(); p2.work(); //return Anonymouse
参看:
- https://carldanley.com/javascript-design-patterns/#creational-design-patterns
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2013-11-15 Javascript 严格模式 strict mode(转)
2013-11-15 多种方法实现div两列等高(收集整理)