background preloader

Writing Fast, Memory-Efficient JavaScript

Writing Fast, Memory-Efficient JavaScript
Advertisement JavaScript engines such as Google’s V81 (Chrome, Node) are specifically designed for the fast execution2 of large JavaScript applications. As you develop, if you care about memory usage and performance, you should be aware of some of what’s going on in your user’s browser’s JavaScript engine behind the scenes. You should, however, ask yourself questions such as: Is there anything I could be doing more efficiently in my code? Fast-loading Web sites — like fast cars — require the use specialized tools. There are many common pitfalls when it comes to writing memory-efficient and fast code, and in this article we’re going to explore some test-proven approaches for writing code that performs better. So, How Does JavaScript Work In V8? While it’s possible to develop large-scale applications without a thorough understanding of JavaScript engines, any car owner will tell you they’ve looked under the hood at least once. Garbage Collection Garbage collection attempts to reclaim memory.

Function.apply and Function.call in JavaScript In order to explain how the createDelegate function works in the last post, we have to understand JavaScript closures and Function.apply(). The apply() method is the easiest subject to tackle, so we'll start there and work up. Every function in JavaScript has a number of attached methods, including toString(), call(), and apply(). If it sounds odd to you that a function might have its own methods - then remember that every function in JavaScript is an object. Because functions are objects they can have their own properties and methods, and we can treat them like data. Let's start with the following code: Here we have a global function by the name of f(). f() uses the this keyword to reference x, but notice we don't invoke the function through an instance of an object. Both call() and apply() are methods we can use to assign the this pointer for the duration of a method invocation. The first invocation of f() will display the value of 10, because this references the global object.

js - jQuery plugin for HTML5+JSON interactive tables and more Demo Processing... To get started, simply install jquery.dynatable.js (along with jQuery), and add the following in the document.ready or after the table: $('#my-table').dynatable(); How it works Dynatable does three things: Read / Normalize The HTML table is scanned and normalized into an array of JSON objects (or collection) where each JSON object (or record) corresponds to a row in the table. This 3-step approach has several advantages: Efficient reading/operating/writing Since the logic and operations occur on the JSON collection, the DOM operations (reading and writing/drawing) are grouped together, making interactions quick and efficient. Normalization The first module normalizes an HTML table into a JSON collection. The following table: Results in this JSON collection: Converting attribute names By default, dynatable converts headings to JSON attribute names using: We could also define our own column-name transformation function. Click the button to the right. Run Code So this: Existing JSON

JavaScript Getters and Setters It is with much happiness that I think I can finally say, without seeming like a fool, that: “JavaScript Getters and Setters are now prevalent enough to become of actual interest to JavaScript developers.” Wow, I’ve been waiting a long time to be able to say that. I want to start by giving a whirlwind tour of Getters and Setters and why they’re useful. Followed by a look into what platforms now support Getters and Setters as to make them relevant. Getters and Setters Getters and Setters allow you to build useful shortcuts for accessing and mutating data within an object. The obvious advantage to writing JavaScript in this manner is that you can use it obscure values that you don’t want the user to directly access. function Field(val){ var value = val; this.getValue = function(){ return value; }; this.setValue = function(val){ value = val; };} Some example results: var field = new Field("test");field.value// => undefinedfield.setValue("test2")field.getValue()// => "test2" Platforms Browsers

Planting A Pineapple — Tickled Red - StumbleUpon Did y’all know that you can take this and turn it into… This? And that this will eventually produce… This? Yes, I’m talking about turning your average, ordinary grocery store pineapple into a tropical showpiece within your home. A plant that is not only impressive but will WOW! Planting a Pineapple 1. 2. 3. In 24 months (sounds better than two years) it will look like this. You will have an actual, large, utterly delicious pineapple in 24-36 months. The thought of growing my own pineapple always makes me smile and giggle just a little bit. Now what am I supposed to do with all of this leftover pineapple? I see something sweet coming soon. While you’re waiting for me to make something yummy with the leftovers, go ahead and plant a pineapple. Be adventurous plant a pineapple. Hugs, Tickled Red *Please bear in mind that I am not a hortoculturist. Tagged as: Gardening, Pineapple, Tropical Fruit

UndeadMan The Ancient Greeks' 6 Words for Love (And Why Knowing Them Can Change Your Li... Looking for an antidote to modern culture's emphasis on romantic love? Perhaps we can learn from the diverse forms of emotional attachment prized by the ancient Greeks. posted Dec 27, 2013 This article originally appeared in Sojourners. Today's coffee culture has an incredibly sophisticated vocabulary. Do you want a cappuccino, an espresso, a skinny latte, or maybe an iced caramel macchiato? Eros involved a loss of control that frightened the Greeks. The ancient Greeks were just as sophisticated in the way they talked about love, recognizing six different varieties. So what were the six loves known to the Greeks? 1. The first kind of love was eros, named after the Greek god of fertility, and it represented the idea of sexual passion and desire. Eros involved a loss of control that frightened the Greeks. 2. The second variety of love was philia or friendship, which the Greeks valued far more than the base sexuality of eros. Like what you're reading? 3. 4. C.S. 5. 6. Read more:

codeheart.js Quantum Consciousness Orchestrated Objective Reduction of Quantum Coherence in Brain Microtubules: The "Orch OR" Model for Consciousness Stuart Hameroff and Roger Penrose Features of consciousness difficult to understand in terms of conventional neuroscience have evoked application of quantum theory, which describes the fundamental behavior of matter and energy. In this paper we propose that aspects of quantum theory (e.g. quantum coherence) and of a newly proposed physical phenomenon of quantum wave function "self-collapse"(objective reduction: OR -Penrose, 1994) are essential for consciousness, and occur in cytoskeletal microtubules and other structures within each of the brain's neurons. Current neurophysiological explanations of consciousness suggest that it is a manifestation of emergent firing patterns of neuronal groups involved in either a) specific networks (e.g. Quantum theory describes the surprising behavior at a fundamental level of matter and energy which comprise our universe. Figure 1.

The guide to implementing 2D platformers | Higher-Order Fun Having previously been disappointed by the information available on the topic, this is my attempt at categorizing different ways to implement 2D platform games, list their strengths and weaknesses, and discuss some implementation details. The long-term goal is to make this an exhaustive and comprehensible guide to the implementation of 2D platform games. If you have any sort of feedback, correction, request, or addition – please leave it in the comments! Disclaimer: some of the information presented here comes from reverse engineering the behavior of the game, not from its code or programmers. I can think of four major ways in which a platform game can be implemented. Type #1: Tile-based (pure) Character movement is limited to tiles, so you can never stand halfway between two tiles. Flashback, shown with tile boundaries Examples: Prince of Persia, Toki Tori, Lode Runner, Flashback How it works Advantages of this system include simplicity and precision. Type #2: Tile Based (Smooth) Slopes

Elle est pas mal du tout cette perle ! by simonw Nov 5

Related: