Oh My JS: The Best JavaScript Articles

Oh My JS: The Best JavaScript Articles

Azat Mardan

Language: English

Pages: 128

ISBN: 2:00241775

Format: PDF / Kindle (mobi) / ePub


Oh My JavaScript

JavaScript is great! It's in the browser and on the server. We love it! But sometime we, JavaScript developers, find topics such as scoping, object instantiating, "this" context, etc. confusing and poorly documents. Oh My JavaScript is a collection of best articles on JavaScript/Node.js which will save your many hours of frustrations and internet searches!

Oh My JavaScript: The Best Article is a compilation of publicly available resources conveniently edited and packaged in an ebook format (PDF, ePub, mobi). Attributions are carefully preserved.

JavaScript syntax and patterns.
Style and Organization

Best practices and conventions.

Best tools for front and back-end development.

Test-Driven Development.

Performance tests and server-side memory testing.

Peculiarities of server-side JavaScript development.















$.extend({}, obj, newObj); 12 13 14 console.log(finalObj.a); //outputs "i am a lonely property" console.log(finalObj.b()); //outputs "i am a lonely function" ECMAScript 5 offers us Object.create(), which you can use to extend from an existing object but you probably need to avoid using this if you need to support older browsers. It does offer distinct advantages to property creation and setting attributes of properties (yes, properties also have properties³⁸). 1 2 3 var obj = { a: 'i am a

lonely property' }; 4 5 6 7 8 9 10 11 var finalObj = Object.create(obj, { b: { get: function() { return "i am a lonely function"; } } }); 12 13 14 console.log(finalObj.a); //outputs "i am a lonely property" console.log(finalObj.b); //outputs "i am a lonely function" You can get pretty deep into the subject of inheritance in JavaScript³⁹ but the beautiful thing here again is that you really don’t have to due to the immense power and flexibility of the language. Bonus Gotcha: Forgetting to use

JSON.stringify(request.headers) + "\n"; 8 9 10 11 // Send answer response.writeHead(200, { "Content-Type": "text/plain" }); response.end(answer); 12 13 }); Restart the server and reload localhost:1337. You’ll see what URL you’re requesting, that it’s a GET request, and that you’ve sent a number of cool headers like the user-agent and more complicated ¹⁸³http://docs.nodejitsu.com/articles/getting-started/what-is-require ¹⁸⁴http://nodejs.org/api/http.html Node.js 109 HTTP stuff! If you

and tough it out with vanilla Node. But you could also build a framework. That’s what Sencha did. And they called it Connect. Middle layer: Connect Fitting that Connect¹⁸⁸ happens to be the middle layer of this JavaScript cake, because it calls itself “a middleware framework for node”. Don’t go searching “what is middleware” just yet – I’m about to explain it. A little bit of Connect code Let’s say we wanted to write the “hello world” app that we had above, but with Connect this time. Don’t

course because JavaScript is not Java¹⁵. The long-term value of software to an organization is in direct proportion to the quality of the codebase. Over its lifetime, a program will be handled by many pairs of hands and eyes. If a program is able to clearly communicate its structure and characteristics, it is less likely that it will break when modified in the never-too-distant future. Code conventions can help in reducing the brittleness of programs. All of our JavaScript code is sent directly

Download sample