JavaScript 设计模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3168805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:31:13  来源:igfitidea点击:

JavaScript design patterns

javascriptdesign-patterns

提问by jerome

This is a question for general discussion. Are there any good, comprehensive resources for useful JavaScript design patterns. I am trying to avoid references that attempt to coerce JavaScript into, say, Java by imposing patterns more suited to another language. Let's let JS be JS and shape our patterns around the strengths.

这是一个一般性讨论的问题。对于有用的 JavaScript 设计模式,是否有任何好的、全面的资源。我试图通过强加更适合另一种语言的模式来避免试图将 JavaScript 强制转换为 Java 的引用。让我们让 JS 成为 JS 并围绕优势塑造我们的模式。

Please any discussion would be valued by more than just me, I suspect.

我怀疑,任何讨论都会受到不仅仅是我的重视。

回答by dpan

回答by friedo

Here's a good one:

这是一个很好的:

回答by Keith.Abramo

This is an awesome book by O'Reilly. It builds on their "JavaScript: The Good Parts".

这是 O'Reilly 的一本很棒的书。它建立在他们的“JavaScript: The Good Parts”之上。

enter image description here

在此处输入图片说明

It references a lot of the patterns mentioned in the "Gang of Four" book and notes a lot of the problems solved in that book are trivial to solve with JavaScript.

它引用了“四人帮”一书中提到的许多模式,并指出该书中解决的许多问题用 JavaScript 解决是微不足道的。

回答by machineghost

APress has a book called "Pro Javascript Design Patterns" that is probably just what you're looking for. While the author (Diaz Harmes) is certainly not "the gang of four", I think he does a pretty good job; I know I learned quite a bit from it (and it got 4.5 stars on Amazon).

APress 有一本名为“Pro Javascript Design Patterns”的书,这可能正是您正在寻找的。虽然作者(迪亚兹哈姆斯)当然不是“四人帮”,但我认为他做得很好;我知道我从中学到了很多东西(它在亚马逊上获得了 4.5 颗星)。

Amazon link: http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X

亚马逊链接:http: //www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X

alt text

替代文字

回答by Sethen

I'm not sure why no one has listed this, but Addy Osmani's JavaScript design pattern book is fantastic and freely available online. He really digs deep to show you the nuts and bolts of each pattern.

我不知道为什么没有人列出这个,但是 Addy Osmani 的 JavaScript 设计模式书很棒并且可以在线免费获得。他真的很深入地向您展示了每种模式的具体细节。

http://addyosmani.com/resources/essentialjsdesignpatterns/book/

http://addyosmani.com/resources/essentialjsdesignpatterns/book/

回答by MilkyWayJoe

This is one of the best design patterns resources I've found for JavaScript http://shichuan.github.com/javascript-patterns/

这是我为 JavaScript 找到的最好的设计模式资源之一 http://shichuan.github.com/javascript-patterns/

It's aimed for JavaScript as we know and not necessarily trying only use concepts of other languages.

正如我们所知,它针对 JavaScript,不一定只尝试使用其他语言的概念。

回答by gblazex

回答by late_riser

As sethen said, I will also suggest for the book of Addy Osmani (http://addyosmani.com/resources/essentialjsdesignpatterns/book/)

正如 sethen 所说,我也会推荐 Addy Osmani 的书(http://addyosmani.com/resources/essentialjsdesignpatterns/book/

Its really cool and easy for beginners. But don't underestimate it to be beginners, the insight described in this book is very thorough and in a meaningful way... To me, it is a must read for all.

对于初学者来说,它真的很酷而且很容易。但是对于初学者来说不要小看它,这本书描述的洞察力非常透彻,而且很有意义......对我来说,这是所有人的必读之作。