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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How CoffeeScript makes jQuery more fun than ever

12 点作者 buhrmi大约 14 年前

2 条评论

Klonoar大约 14 年前
While I like CoffeeScript, I feel I need to note that this isn't really a great example - in fact, I'd call it an incorrect example:<p><pre><code> var elem, formValues; formValues = (function() { var _i, _len, _ref, _results; _ref = $('.input'); _results = []; for (_i = 0, _len = _ref.length; _i &#60; _len; _i++) { elem = _ref[_i]; _results.push(elem.value); } return _results; })(); </code></pre> That's... needlessly <i>bad</i>, so to speak. That could be rewritten in a much more readable fashion, like so:<p><pre><code> var formValues = (function(inputEls) { var results = []; inputEls.each(function() { results.push($(this).val()); }); return results; })($('.input')); </code></pre> If CoffeeScript is generating the first block seen here, then I'd actually be concerned, but perhaps I care more about this than some. Either way, while...<p><pre><code> formValues = (elem.value for elem in $('.input')) </code></pre> ...is certainly nicer, I don't really think it's necessary to further bastardize the views held on Javascript syntax in general. The first block in this comment is, to put it bluntly, <i>utter shit</i>, and does nothing but continue the trend that "oh god Javascript is horrible".
评论 #2534911 未加载
ddemchuk大约 14 年前
I guess I could be ignorant here, but I don't really feel that Coffeescript makes things easier/more elegant/better than just using jQuery. I'm not particularly a fan of abstracting abstractions in the first place so I'm probably biased, but I find jQuery to be clean and concise already. An example from the article:<p>$.post(<p><pre><code> "/posts/update_title" new_title: input.val() id: something -&#62; alert('done') 'json' </code></pre> )<p>All coffeescript really did there was remove the commas and subtly change the syntax. That's not an improvement at all, it's just a lateral syntax change. If anything, the lack of commas almost makes it harder to read.<p>Why change to coffeescript and add another step (compilation of coffeescripts) into the mix when jquery was already pretty good to start with? Just seems like its something that would make it hard to take on new coders when your business starts scaling because they would need to know yet another meta-abstraction.
评论 #2534881 未加载