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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

JavaScript Garden

397 点作者 aundumla大约 14 年前

19 条评论

tkiley大约 14 年前
Excellent write-up! I've learned most of these things the hard way :/ I'm filing this away to recommend to any developers who are setting out to use Javascript extensively for the first time.<p>One quibble: In the "common pitfalls" section regarding the "this" object, they say that locally-defined functions within other functions <i>never</i> have any practical use. I might disagree: with a little coaxing, you can convince locally variables inside the constructor (both functions and other variables) to serve as private properties of an object; this is the only technique I know that allows for private properties.<p>(I haven't actually done this in code that has been maintained/used anywhere, I just did it as an experiment and filed it away as a "that's cool" for future reference)<p>Edit: Here is an example of what I'm talking about: <a href="https://gist.github.com/866103" rel="nofollow">https://gist.github.com/866103</a>
评论 #2313985 未加载
评论 #2314377 未加载
评论 #2313843 未加载
csomar大约 14 年前
Does anyone have an idea of what happened to "The secrets of the JavaScript ninja"? I'm impatiently waiting for this book to be released.
评论 #2313697 未加载
评论 #2313550 未加载
mrspeaker大约 14 年前
This looks like an excellent resource for when you are too lazy to get up out of your chair and pick up your copy of "JavaScript: The Good Parts" ;)
评论 #2315113 未加载
评论 #2313472 未加载
andreyf大约 14 年前
In the prototype example [1], could someone explain the point or at least the effect of setting Bar.prototype.constructor = Bar?<p>1. <a href="http://bonsaiden.github.com/JavaScript-Garden/#prototype" rel="nofollow">http://bonsaiden.github.com/JavaScript-Garden/#prototype</a>
评论 #2313783 未加载
senorpedro大约 14 年前
similar: <a href="http://wtfjs.com/" rel="nofollow">http://wtfjs.com/</a>
extension大约 14 年前
<i>the native prototypes should never be extended unless it is for the sake of compatibility with newer JavaScript features</i><p>A bit controversial, don't you think?
评论 #2313787 未加载
Kilimanjaro大约 14 年前
Everyday you learn something new<p><pre><code> Number.prototype.times=function(fn){ for(i=0;i&#60;this;i++){ fn(i); } } 3..times(alert)</code></pre>
评论 #2316203 未加载
评论 #2315732 未加载
btipling大约 14 年前
Should probably also mention the Function constructor in the eval section. Also object keys are always are type cast into strings so object[1] = "moo" becomes object["1"], this is rarely a problem but can be.
ck2大约 14 年前
Very well done.<p>I'd add under <i>setTimeout and setInterval</i> that anything below <i>8ms</i> may not work as expected across different browsers/hardware. Even setting <i>1ms</i> to indicate "as soon as possible" may not occur as expected when repeatedly called.<p>also: the font size is a little small for my eyes in the code boxes - I can fix it of course with stylish but maybe that can be addressed directly on the site
评论 #2315184 未加载
tomelders大约 14 年前
I've seen so many people insist that Javascript code should be Semicolon free recently. It always felt wrong to me, mainly because I code in several languages and getting into the habit of not using semicolons felt dangerous. It's nice to know there's a genuine reason to continue using them.
roryokane大约 14 年前
This site is too light on details for me to trust its conclusions.<p>Under “The evil eval”, it concludes that you should never use eval simply because it sometimes executes in global scope. That does not seem like an obvious conclusion to me. Yes, it’s a mistake to use it on user input, but that is easily avoided. I think the site should give an example of a situation where you think you need eval, the problems eval <i>necessarily</i> brings in that case, and how to write that without eval. Otherwise, I don’t trust that the site writer has actually explored why people use eval or what eval might be able to provide that nothing else can.<p>Also, under “Automatic semicolon insertion”, the site does not mention the alternative to using semicolons everywhere, which is not using semicolons but remembering to put a semicolon before each line starting with parentheses. That is a valid alternate practice, and the site ignores the possibility without even discussing its problems.<p>The fact that each of those two sections contain grammar mistakes (comma splices) also signals a lack of attention to detail.
评论 #2320607 未加载
alexyim大约 14 年前
One gotcha I've noticed a lot is when people forget to check for Console object. Or they might do this (doesn't work):<p><pre><code> if(!console) </code></pre> instead of<p><pre><code> if(!window.console) or if( typeof console === 'undefined' )</code></pre>
评论 #2315247 未加载
koraybalci大约 14 年前
great design (in addition to the content). How did you make it? I like the right contents column changing topic as I read.
评论 #2313934 未加载
hanifvirani大约 14 年前
Looks helpful and is neatly presented. It would be great to have something like this replicated for other languages.
sawyer大约 14 年前
Love it; I'll definitely switch to strict equality comparisons from now on!
Ruudjah大约 14 年前
Well written, clear syntax highlighted examples. Upboat.
kifou1大约 14 年前
Thanks for the tips, very intresting
simpsond大约 14 年前
Very good job.
wkasel大约 14 年前
Very useful.