5 ms·
Offer HN: I'll answer your javascript questions
I'll gladly answer javascript questions this weekend if you have any.
geuis.teses@gmail.com
- GrandMasterBirt 16y agoOk: 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 16y agoencapsulation?
- GrandMasterBirt 16y agocomposition. Told you 15 minutes later.
- barrydahlberg 16y agoHave 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 16y agoCoffeescript 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.
- psykotic 16y agoThat's a pretty lame excuse. There also isn't a simple line for line relationship between C code and x86 code or C# code and MSIL code. But there's a standard solution to this problem when debugging: let the compilers generate mapping information. For something like CoffeeScript, you'd probably have a debug compilation mode where each line of generated code is annotated with comments containing line numbers or full lines of code from the original CoffeeScript source code. It wouldn't be as convenient as a true source-level debugger for CoffeeScript, but it should suffice.
- Scriptor 16y agoAs far as I'm aware, there is no such debugging mode for CoffeeScript. The current method of debugging really is to look in the JS and then find the corresponding CS code. They do make this easier by keeping the JS code as readable as possible.
- psykotic 16y agoOh, I know. I was saying that it would be doable to implement.
- deleted 16y ago[deleted]
- jashkenas 16y agoThe 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 https://bugzilla.mozilla.org/show_bug.cgi?id=618650 http://intertwingly.net/blog/2010/11/25/Hobgoblin-of-Little-Minds http://intertwingly.net/blog/2010/11/25/Hobgoblin-of-Little-...
- GrandMasterBirt 16y agoIn 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 16y agoLook at RequireJS, http://requirejs.org/ http://requirejs.org/
- brianwillis 16y agoI'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?
- dekz 16y agoYou don't even need to learn javascript for web dev, checkout a project called Coffeescript.
- lukeinth 16y agoI'm a big CoffeeScript fan, but I would never say just learn CoffeeScript and skip JavaScript. CoffeeScript is really just syntax and abstraction on top of JavaScript.
- maxwell 16y agojQuery is just the de facto DOM API; learn them concurrently.
- geuis 16y agoI wouldn't agree with this 100%. I principally use jQuery unless I am working on something that has to very lightweight. However, there are lots of libraries and different reasons people and companies use them. That's why it's important to know the language in detail so that you can switch between libraries as needed.
- kls 16y agoRight, there is also Dojo hanging out there for large browser Apps. There is a point in which you can outgrow jQuery due to the size and complexity of an application. Dojo kind of fills that upper end so while it is a smaller segment of the market, there are still other toolkits that hold their share of the market for what they are tailored for. In saying that, there are some newer, complementary projects like backbone that are trying to make large web app development in jQuery less painful, but as of right now Dojo owns that space and it remains to be seen if that will change.
- windsurfer 16y agoWhat'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 16y agoNode 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/ 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 16y agoFor 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/CompilerOptimizations 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?
- heyrhett 16y agosetTimeout drives me crazy. How can I implement "sleep" without going insane?
- johnswamps 16y agoYour 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.
- geuis 16y agoSo 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 16y agoIMO, 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 16y agoExcept that you basically wrote the same thing as my second example, except your functions aren't namespaced and are polluting globals.
- sarenji 16y agoCould 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."
- geuis 16y agoPlease email me at geuis.teses@gmail.com. Bit easier to handle questions there.
- aiurtourist 16y agoWhat'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 16y agoSay 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?