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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Encapsulation in Javascript

24 点作者 Aviwein77超过 13 年前
Thought that it was interesting and others might enjoy it as well.

3 条评论

jashkenas超过 13 年前
Not to be hyperbolic, but the continual promotion of the "module" pattern in JavaScript is some of the worst advice you can give.<p>JavaScript has prototypes for a reason -- use them. By using the "module" pattern to build objects, you create a separate copy of every function for every instance of every object you create. If you're just creating a handful of objects, it's no big deal, but if you're creating a large number of objects, it's horribly CPU and memory inefficient.<p>Modern JS runtimes like Chrome/V8 can create and store a million small objects with prototypes and "new" in a couple seconds, using just a dozen or so megabytes of RAM. Creating the same million small objects with the "module" pattern takes minutes, uses many hundreds of megabytes of memory, and often crashes the browser.<p>And that's just the pragmatics -- there are deeper semantic reasons to use real prototypes.
评论 #2992502 未加载
评论 #2991972 未加载
评论 #2992120 未加载
评论 #2992128 未加载
评论 #2992123 未加载
latchkey超过 13 年前
CoffeeScript FTW. <a href="https://gist.github.com/1214296" rel="nofollow">https://gist.github.com/1214296</a>
primo44超过 13 年前
"Module's are where it's at"?<p>Grammar much?<p>And don't get me started on "login with X, Y, Z". As a verb, it's "log in". YC has it wrong also.
评论 #2992995 未加载