TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Strategy Pattern in JavaScript

30 点作者 jugglinmike将近 14 年前

6 条评论

teej将近 14 年前
I'm surprised the author didn't mention the use case where I've seen this most often: animation easing. In every JS library I've seen, the strategy pattern was used for easing functions.
评论 #2680235 未加载
cpr将近 14 年前
Sorry, but (coming from a 40-years-of-software-development grizzled veteran), I don't see any new pattern here. Just good old-fashioned modularity.<p>Perhaps I missed the point?
评论 #2681034 未加载
评论 #2680451 未加载
kuroir将近 14 年前
Try jQuery Condom, which allows you to make namespaces jQuery Plugins on the fly and override jQuery functionality without touching the global namespace (modularity).<p><a href="https://github.com/kuroir/jQuery-Condom" rel="nofollow">https://github.com/kuroir/jQuery-Condom</a>
jbwyme将近 14 年前
Tell me if I have this straight: this pattern basically says to create a generic object with properties and handlers to allow for simple iteration, creation, etc. like you would with an interface. Then, if needed, use a prototype to set defaults?
评论 #2680439 未加载
eridius将近 14 年前
Funny, this looks precisely like basic object-oriented programming.
MostAwesomeDude将近 14 年前
In Python, at least, this pattern is called the "dispatch dictionary" and relies on the ability of Python to store just about anything as dictionary values. It is considered to be Python's answer to the question, "Why is there no switch/case in Python?"