
Offer HN: I'll answer your javascript questions - geuis
I'll gladly answer javascript questions this weekend if you have any.<p>geuis.teses@gmail.com
======
brianwillis
I'm a desktop application developer still finding my feet on the web. Should I
bother learning "pure" JavaScript or should I just learn a library like
JQuery?

~~~
gte910h
If you're a desktop guy, and MS based, learn some silverlight, it's very nice
and also a MS-win7 phone.

If you're not, Javascript + JQuery is the way to learn for the client side
stuff, you also need a server side language (python, ruby, etc).

~~~
pshirishreddy
If possible can you throw some light on which would be good for starters on
server side language Python (which I am currently learning) from
[http://learnpythonthehardway.org/static/LearnPythonTheHardWa...](http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf)
OR PHP (which I already know)

~~~
barrydahlberg
Python is generally considered to be the stronger language and certainly the
one I would recommend.

~~~
pshirishreddy
then I am at it.. :) thank you.

------
sarenji
Could you explain prototypes? Most of what I learned about prototypes are
hands-on. Maybe it's just me but I find there's a lack of good explanations
out there and it would be really useful to have an answer that says, "Here are
prototypes in their entirety."

------
barrydahlberg
Have you tried CoffeeScript and what are your thoughts on it? It's clearly not
'done' yet but I found it really helps clean up my scripts, reduce the amount
of typing and avoid a lot of tricky JavaScript mistakes.

~~~
ramanujan
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 Coffeescript
itself, not sure how to fix that.

~~~
jashkenas
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
(starting as soon as Firefox 4, perhaps) have plans to add better support for
compile-to-JavaScript languages.

<https://bugzilla.mozilla.org/show_bug.cgi?id=618650>

[http://intertwingly.net/blog/2010/11/25/Hobgoblin-of-
Little-...](http://intertwingly.net/blog/2010/11/25/Hobgoblin-of-Little-Minds)

~~~
pdelgallego
>The browser vendors (starting as soon as Firefox 4, perhaps) have plans to
add better support for compile-to-JavaScript languages

That are great news, Do you thing we will see many new languages that compile
to JS in the near future?

------
aiurtourist
What's the best JavaScript deployment strategy you've seen?

I.e., are assets always compiled and bundled? How do you split up your
bundles? Would you use namespaces, like Closure? How do you handle
dependencies? What percent of the code lives on the page in script tags versus
external resources? What testing framework(s) do you use? Do you prefer a
certain code style?

------
tomfluff
Say i have a bookmarklet with the following code

javascript:(function(){q=document.getElementById("question-
title").getElementsByTagName("b")[0].innerHTML.split(" ",3);})();

That is only a snippet of the code but you get the idea.

Is it possible to repeat the code every 3-5 seconds in a bookmarklet?

------
heyrhett
setTimeout drives me crazy. How can I implement "sleep" without going insane?

~~~
geuis
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 pattern:

var obj = { sleep: function(fn, time){ setTimeout(fn, time ); }, func1:
function(data){ console.log('Continuing'); }, init: function(data){

    
    
            console.log('Starting');
            obj.sleep(obj.func1, 2000);
        }

} obj.init()

~~~
psykotic
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);

~~~
geuis
Except that you basically wrote the same thing as my second example, except
your functions aren't namespaced and are polluting globals.

------
windsurfer
What'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.

~~~
geuis
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://learningwebgl.com/> to get started.

MooTools is mainly a client-side library. I've found that its syntax, like
that of YUI and Prototype are excessive and limited. While you can use any
library to get the same work done, I've stuck with jQuery because its just
more natural for me to work with it. Its syntax, features, and widespread
support are all positive reasons to use jQuery over other libraries.

GWT was designed to let Java engineers write javascript in Java. That's just a
bad, bad idea. The resulting javascript code doesn't really take advantage of
the language the way it was designed. It helps Java engineers feel like they
can write web stuff, but really the end result is not often very pretty.

~~~
jhuni
For small scripts there is no reason to use GWT, however, for large AJAX
applications it can be incredibly advantageous.

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...](http://code.google.com/p/google-web-
toolkit/wiki/CompilerOptimizations)

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?

------
geuis
Please email me at geuis.teses@gmail.com. Bit easier to handle questions
there.

------
GrandMasterBirt
Ok: What are some good object creation strategies you employ. Basically I know
with javascript there are a handful of different ways to create objects. Some
(using a framework) give you java-like inheritence, some other methodologies.
Much of the time you don't really need to give a shit about inheritence as you
are more focused on containership (the word eludes me, probably will remember
it 15 minutes after post).

So what to do you? Do you even code javascript now or you use coffeescript and
it's object creation strats (or do you use clojure, or whatever).

And another question: Do you use JSLint or something similar? What about if
you want to validate javascriopt 1.7/1.8 syntax.

~~~
dekz
encapsulation?

~~~
GrandMasterBirt
composition. Told you 15 minutes later.

------
GrandMasterBirt
In a browser, what framework do you use to handle file dependencies? As in I
have foo.js which will only run if bar.js is loaded, I don't want to specify
in my page: 1) load bar.js, 2) load foo.js 3) order matters... rather I want
to say load foo.js (and implicitly it loads bar.js first)

~~~
geuis
Look at RequireJS, <http://requirejs.org/>

