Live data from Hacker News

Offer HN: I'll answer your javascript questions

news.ycombinator.com

11–20 of 45 posts

Re: Offer HN: I'll answer your javascript questions

#11
post #4

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

Your problem is not with setTimeout, you need to learn how to write evented code because that is how javascript works and you're going to encounter this problem in different contexts. Passing in a closure to setTimeout usually suffices though, it's just slightly uglier than a normal "sleep" call.

If you really, really wanted to you could create a busy wait sleep function, but it's an awful idea and you should never do it.

Re: Offer HN: I'll answer your javascript questions

#12

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.

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.

Re: Offer HN: I'll answer your javascript questions

#13
post #4

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

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()

Re: Offer HN: I'll answer your javascript questions

#14
post #9

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?

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).

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... OR PHP (which I already know)

Re: Offer HN: I'll answer your javascript questions

#15
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.

Re: Offer HN: I'll answer your javascript questions

#16
post #9

Earlier quoted context omitted.

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).

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... OR PHP (which I already know)

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

Re: Offer HN: I'll answer your javascript questions

#18
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)

Re: Offer HN: I'll answer your javascript questions

#19

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)

Look at RequireJS, http://requirejs.org/

Re: Offer HN: I'll answer your javascript questions

#20

Earlier quoted context omitted.

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... OR PHP (which I already know)

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

then I am at it.. :) thank you.
Post reply on HN