Earlier quoted context omitted.
So you should never think of "sleep" in javascript. Since the language is single-threaded, really if you pause the script you're pausing the entire environment (whether its in the browser or on the server in something like Node.js). But, to answer your question: // some code runs here var continue = function(data){ //more code runs in here after sleep } setTimeout(function(){ continue(data); },2000); A different patt…
IMO, a better pattern is to use lexical closures in continuation-passing style to share state: function sleep(time, continuation) { setTimeout(continuation, time); } function start_process(x) { var y = foo(x); sleep(1000, function() { var z = bar(x, y); sleep(2000, function() { baz(x, y, z); });}); } start_process(42);
Offer HN: I'll answer your javascript questions
41–45 of 45 posts
Re: Offer HN: I'll answer your javascript questions
#42What's your opinion of technologies like Node, WebGL, MooTools, and GWT? All are interesting to me but I'm not sure where to invest my time.
Node is a server-side js environment. I use it all the time now and its awesome. I still use Python & Django for web development, but in the next few years I will feel completely comfortable switching over to a javascript stack entirely. WebGL is something I haven't played with much, mainly due to small market share yet. With so much out there, I've had to prioritize on what to learn and when. I recommend http://lear…
GWT performs comprehensive optimizations - in-lining methods, limiting property access, removing dead code, limiting code size, and more.
http://code.google.com/p/google-web-toolkit/wiki/CompilerOpt...
As a result of all of these optimizations, GWT can produce code that is as fast if not faster then hand written JavaScript. The reason for this is that most large JavaScript projects tend to use a lot of dynamic features (such as dynamic binding) and other conveniences instead of writing super optimized JavaScript code by hand.
Also care to explain what you mean when you say "It helps Java engineers feel like they can write web stuff" are you implying that JavaScript engineers create "web stuff" well Java engineers don't?
Re: Offer HN: I'll answer your javascript questions
#43Earlier quoted context omitted.
Coffeescript is great in theory. The problem is that when debugging stuff in the browser, you're going to be looking at Javascript in Chrome Developer Tools or Firebug. You can hopefully do an inverse mapping from generated JS to the corresponding line in Coffeescript...but that's kind of a pain, especially because it's not a line for line conversion. Short of patching Chrome Dev Tools to support stepping through Cof…
The truth, (and a big part of the reason why we haven't already tried to solve this), is that it hasn't posed a problem for folks who are building apps in CoffeeScript. The transformation is straightforward enough that by glancing at the line number mentioned in the JavaScript, it's immediately obvious where the problem is in the CoffeeScript. That said, I'd love to have a true solid debugger. The browser vendors (st…
That are great news, Do you thing we will see many new languages that compile to JS in the near future?
Re: Offer HN: I'll answer your javascript questions
#44Earlier quoted context omitted.
Coffeescript is great in theory. The problem is that when debugging stuff in the browser, you're going to be looking at Javascript in Chrome Developer Tools or Firebug. You can hopefully do an inverse mapping from generated JS to the corresponding line in Coffeescript...but that's kind of a pain, especially because it's not a line for line conversion. Short of patching Chrome Dev Tools to support stepping through Cof…
The truth, (and a big part of the reason why we haven't already tried to solve this), is that it hasn't posed a problem for folks who are building apps in CoffeeScript. The transformation is straightforward enough that by glancing at the line number mentioned in the JavaScript, it's immediately obvious where the problem is in the CoffeeScript. That said, I'd love to have a true solid debugger. The browser vendors (st…
Re: Offer HN: I'll answer your javascript questions
#45Earlier quoted context omitted.
Coffeescript is great in theory. The problem is that when debugging stuff in the browser, you're going to be looking at Javascript in Chrome Developer Tools or Firebug. You can hopefully do an inverse mapping from generated JS to the corresponding line in Coffeescript...but that's kind of a pain, especially because it's not a line for line conversion. Short of patching Chrome Dev Tools to support stepping through Cof…
The truth, (and a big part of the reason why we haven't already tried to solve this), is that it hasn't posed a problem for folks who are building apps in CoffeeScript. The transformation is straightforward enough that by glancing at the line number mentioned in the JavaScript, it's immediately obvious where the problem is in the CoffeeScript. That said, I'd love to have a true solid debugger. The browser vendors (st…