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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

JavaScript best practices

93 点作者 arash_milani将近 10 年前

12 条评论

TheAceOfHearts将近 10 年前
Glancing at this, it has some clearly outdated information... And it has a lot of links but I don&#x27;t see a lot of meaty information. It&#x27;s very shallow.<p>JS best practices are questionable at best. As an example, when React came out everyone was saying how much of a terrible idea it was (with me being one of those people, unfortunately), and how templates and code should be kept separate... But then I tried it, and I realized just how wrong I was. It makes a lot of sense to keep related things together. Your component&#x27;s logic &#x2F; template can be in one place, and your <i>application</i> logic is kept elsewhere.<p>I read a lot about JS, and I get the impression a lot of people are just hacking together websites with JS sprinkled on top, or hackathon-style apps that they don&#x27;t plan on maintaining for longer that a few weeks. So their &quot;best practices&quot; end up being questionable at best. Basically, who are you to claim that whatever you&#x27;re doing is a &quot;best practice&quot;? It seems like a pretty bold claim, so I&#x27;d argue that it&#x27;s not unreasonable to expect someone to back up their claims.<p>As a side-note, why don&#x27;t people ever talk about testing? And not just linking to some tools, but actually talking about how you figure out <i>what</i> things are worth testing, and <i>how</i> you test em.
评论 #9834818 未加载
评论 #9833761 未加载
评论 #9834137 未加载
评论 #9833092 未加载
评论 #9833505 未加载
haberman将近 10 年前
This is great, but what I think is sorely needed is a roadmap to navigating the maze of module systems, transpilers, preprocessors, packagers, etc.<p>Why do npm and bower both exist? What is the difference between UglifyJS and Closure Compiler? Do I want WebPack or Browserify? Should I use these standalone or should I use them together with Gulp, Grunt, or another build tool? Which of the hundreds or thousands of plugins for the build tools should I use (Gulp has 1,532 plugins and Grunt has 4,403!!)? Should I use CommonJS, ES6 modules, AMD, UMD, or something else? Don&#x27;t even get me started on application-level frameworks like React, Angular, Ember, etc.<p>I have reasonably good answers to these questions in my head right now, but three days ago I had no clue. And it really is a maze, because while all of these projects have flashy web pages and nifty &quot;getting started&quot; guides, their docs rarely explain the role of their tool in the big picture, and its relationship to other tools, they just give you examples and point to recipes. And there aren&#x27;t a set of best practices for setting up a project that cover 99% of common needs painlessly -- you really have to get your hands dirty and configure the tools, in my experience.<p>I mean, take a step back and writing JavaScript in 2015 is pretty weird. Writing JavaScript in Node.js involves writing things like require() that the browser doesn&#x27;t understand at all. So you have to run code like that through a tool before you can use it in a browser at all. But what tool exactly? There are so many to choose from, all of which have their own way of being configured. To write JavaScript in 2015, you basically have to sit down and choose a language dialect design a compiler pipeline to match.<p>I mean, just look at the Babel &quot;setup&quot; guide and how many different variations there are in the instructions based on what tools&#x2F;frameworks you are using! <a href="https:&#x2F;&#x2F;babeljs.io&#x2F;docs&#x2F;setup&#x2F;#make" rel="nofollow">https:&#x2F;&#x2F;babeljs.io&#x2F;docs&#x2F;setup&#x2F;#make</a><p>The point of all this isn&#x27;t to criticize, but more to offer my experience of being extremely confused&#x2F;overwhelmed.<p>Hopefully a lot of this will get better once ES6 is ubiquitous.
评论 #9832960 未加载
评论 #9833959 未加载
yeskia将近 10 年前
Was hoping this would be similar to PHP: The Right Way (<a href="http:&#x2F;&#x2F;www.phptherightway.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.phptherightway.com&#x2F;</a>) where everything you need to know is on the one page with links for more information available, rather than just links to other sites.
babby将近 10 年前
This is a mostly garbage. It doesn&#x27;t even mention control flow; callbacks, promises.<p>A big problem with JS is in part its best quality; flexibility. New and old developers need to be shown how JS has evolved to be written. I see massive code-quality and structure discrepancies in various large modules throughout the JS community and it only serves to dissuade contribution.<p>I&#x27;m not sure if it exists, but there should instead be a site dedicated to: &quot;JS, done right.&quot;<p>It could outline actual best practices. - Building, usage of precompilers - Control flow - Code structures - Tests - Everything in between<p>Usage of precompilers. - Browserify, for modularity - Babel, for next-gen features and code elegance<p>Control flow - Bluebird, for promises<p>Tests - What libraries to use - How to build tests and how the big guys do it - Guides for complex tests<p>Then you could introduce other somewhat subjective deviations, like CoffeeScript, other promise libraries, other control flow techniques.<p>Describing code structures is another big one. With the use of Babel, the example-code can feature ES6 classes which would remove a nice chunk of the confusion newbs might associate with JS&#x27;s prototype system (Not to say it shouldn&#x27;t be introduced).<p>Then describe when to use each code structure.<p>My last thought would be to link to Github repos; for example, applications in both node.js and the client, which could describe a standardized filestructure, explain build steps, introduce tests, supply a step by step guide, etc..<p>Then I might say that if someone makes it through that gauntlet (and everything I missed in between), they might just be a competent JS dev.
omgtehlion将近 10 年前
Loads of bullshit if you ask me.<p>e.g. &quot;Singleton pattern in JS&quot;: var x = {}, that’s enough, folks, do not write pages of code when all you need is just one line.
jamesrom将近 10 年前
Whoever made this page: have you actually tried to use it?<p>I&#x27;m confident that all of this could fit neatly on 3 or 4 vertical scrolls (not 20+ as it stands currently)... Without making any compromise to readability, without the rainbow zebra bands.
csvan将近 10 年前
Not sure why hoisting is listed under &quot;the good parts&quot;
评论 #9832776 未加载
评论 #9832866 未加载
moopsy将近 10 年前
TL;DR just read this book <a href="http:&#x2F;&#x2F;addyosmani.com&#x2F;resources&#x2F;essentialjsdesignpatterns&#x2F;book&#x2F;" rel="nofollow">http:&#x2F;&#x2F;addyosmani.com&#x2F;resources&#x2F;essentialjsdesignpatterns&#x2F;bo...</a>
erokar将近 10 年前
JS isn&#x27;t Java. It usually doesn&#x27;t need the design patterns of more brittle OOP languages.
threatofrain将近 10 年前
Aren&#x27;t there way too many options for something advertised to a beginner? Shouldn&#x27;t one dare to have a pedagogical opinion and so curate?
github-cat将近 10 年前
It&#x27;s a good guideline for JavaScript developers though there are more to be added.
mandeepj将近 10 年前
Great content and organization but awful layout and design. Sorry for being negative.