background preloader

Naked JavaScript

Facebook Twitter

Documentation - Where can I find information about Javascript engine internals? Writing a Non-blocking JavaScript Quicksort - Jimmy Breck-McKye. I’ve recently had some fun writing a browser quicksort.

Writing a Non-blocking JavaScript Quicksort - Jimmy Breck-McKye

As part of a recent project, I had to implement a Knockout table component that could sort and filter its entries in realtime. This would normally have been straightforward, except for a handful of use-cases where the table would contain upwards of three thousand entries – possibly more. Calling a native array sort() on such a large set with a particularly complex comparator would force IE8 to freeze for several seconds and throw a long running script error.

Server-side sorting was awkward for various reasons, and we weren’t terribly keen on the complications that AJAX imposed. What we really wanted was a non-blocking JavaScript sort. Investigating the long running script exception If you’ve done any heavy lifting with JavaScript in IE8, you’ve probably seen the following exception: The exception is triggered by a maximum statement count. Stopping it from appearing My immediate thought was to write a quicksort. What No One Told You About Z-Index — Philip Walton. The problem with z-index is that very few people understand how it really works.

What No One Told You About Z-Index — Philip Walton

It’s not complicated, but it if you’ve never taken the time to read its specification, there are almost certainly crucial aspects that you’re completely unaware of. Don’t believe me? Well, see if you can solve this problem: The Problem In the following HTML you have three <div> elements, and each <div> contains a single <span> element. Here’s what the HTML and basic CSS look like. <div><span class="red">Red</span></div><div><span class="green">Green</span></div><div><span class="blue">Blue</span></div> Here’s the challenge: try to see if you can make the red <span> element stack behind the blue and green <span> elements without breaking any of the following rules: Do not alter the HTML markup in any way.

To see if you can figure it out, click the edit on Codepen link above and play around with it for a bit. Warning: Don’t click on the CSS tab of the example below or it will give away the answer. The Solution. We Tested How Googlebot Crawls Javascript And Here's What We Learned.

JS tools and design

JS Theory. Events and timing in-depth. Internally, the browsers are event-driven.

Events and timing in-depth

Most actions occur asynchronously and create an event which is appended to the queue. They are taken from the queue and processed when the time permits. For example: A script has finished loading.Keypress, mousemove.The window is resized. Many events are integrated with JavaScript and many events are strictly internal. JavaScript is single-threaded There is only one JavaScript thread per window.

There is a Web Workers standard (incomplete at the time of writing) which defines the support for multiple JavaScript workers. Web workers are limited. Asynchronous events Most events are asynchronous. When an asynchronous event occurs, it gets into the Event queue. The browser has inner loop, called Event Loop, which checks the queue and processes events, executes functions etc. For example, if the browser is busy processing your onclick, and another event happened in the background (like script onload), it appends to the queue.

JavaScript’s Apply, Call, and Bind Methods are Essential for JavaScript Professionals. Prerequisite: — Understand JavaScript’s “this” With Ease, and Master It. — JavaScript Objects — Understand JavaScript Closures (This is an intermediate to advanced topic) Duration: About 40 minutes.

JavaScript’s Apply, Call, and Bind Methods are Essential for JavaScript Professionals

Functions are objects in JavaScript, as you should know by now, if you have read any of the prerequisite articles. And as objects, functions have methods, including the powerful Apply, Call, and Bind methods. On the one hand, Apply and Call are nearly identical and are frequently used in JavaScript for borrowing methods and for setting the this value explicitly. We also use Apply for variable-arity functions; you will learn more about this in a bit. Understanding Design Patterns in JavaScript.

Today, we're going to put on our computer science hats as we learn about some common design patterns.

Understanding Design Patterns in JavaScript

Design patterns offer developers ways to solve technical problems in a reusable and elegant way. Interested in becoming a better JavaScript developer? Then read on. Republished Tutorial Every few weeks, we revisit some of our reader's favorite posts from throughout the history of the site. Solid design patterns are the basic building block for maintainable software applications. A design pattern is a reusable software solution Simply put, a design pattern is a reusable software solution to a specific type of problem that occurs frequently when developing software.

Patterns are proven solutions to software development problems patterns are scalable as they usually are structured and have rules that you should follow patterns are reusable for similar problems We'll get into some examples of design patterns further in to the tutorial. JavaScript_Enlightenment.pdf. Object.create() The Object.create() method creates a new object with the specified prototype object and properties.

Object.create()

SyntaxEdit Object.create([, ]) Parameters proto The object which should be the prototype of the newly-created object. propertiesObject.