background preloader

Code and Examples

Facebook Twitter

Checking if an associative array key exists in Javascript. Sorting JavaScript Object by property value. How to get all properties values of a Javascript Object (without knowing the keys) How can I add a key/value pair to a JavaScript object literal. Gray Color Combinations. The Combo Library contains pages of gray color combinations (a.k.a, color schemes and color palettes) for you to choose from.

Gray Color Combinations

Each color scheme contains the html color codes you will need when coding your website template. The hex codes can be found underneath each of the color swatches. Click on a color combinations name to test it out. This link will take you to the Combo Tester, where you can view a larger version of each color palette. The Combo Library provides a convenient way to search gray color schemes. You can click on individual hex color codes to view them full screen through the Combo Tester. Flash of Unstyled Content (FOUC) What is a FOUC?

Flash of Unstyled Content (FOUC)

Some pages that use the CSS @import rule experience a curious display quirk in the Windows version of MS Internet Explorer: a momentary flash of unstyled page content. The unimaginative creature that I am, I call this phenomenon Flash of Unstyled Content or FOUC for short. Because this quirk seems to affect only MS Internet Explorer, we're tempted to conclude that IE is just plain wrong. I am not going to jump to that conclusion. It is unclear to me whether or not a FOUC afflicted user agent is in disagreement with any W3C recommendation. How do I see a FOUC?

First, you will need to be using IE for Windows (version 5 or above). Now, this is very important. Load the page that you want to test into an IE5+/Win browser window. Please note that some factors, like a slow PC or proximity to network equipment with caching capabilities, may reduce the chance that you'll witness the flash of unstyled content display quirk. What's the backstory? Javascript Closures.

Introduction Closure A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).

Javascript Closures

Closures are one of the most powerful features of ECMAScript (javascript) but they cannot be property exploited without understanding them. They are, however, relatively easy to create, even accidentally, and their creation has potentially harmful consequences, particularly in some relatively common web browser environments. To avoid accidentally encountering the drawbacks and to take advantage of the benefits they offer it is necessary to understand their mechanism.

This depends heavily on the role of scope chains in identifier resolution and so on the resolution of property names on objects. Hoisting en Javascript. Recientemente un viejo colega (@f5inet) me pedía una breve introducción al uso de las variables en Javascript.

Hoisting en Javascript

Explicándole por encima las normas básicas, llegué a uno de los puntos que más confusión despiertan y que son una fuente frecuente de errores para los programadores noveles: el hoisting. El hoisting (“elevación”) en Javascript es una de esas particularidades del lenguaje sobre la que la comunidad de desarrolladores no llega a ponerse de acuerdo en si se trata de un bug o una feature. Para John Resig, manejado correctamente, es un poderoso aliado a la hora de gestionar los ámbitos que alcanzan nuestras variables; para otros como Douglas Crackford, su descuido se convierte inmediatamente en inconsistencias en nuestros códigos y errores potenciales difíciles después de identificar y depurar. Understanding Scope and Binding in JavaScript. At the heart of binding, it’s merely a means to control execution scope—Function x executions in the scope of object y .

It can be tough to grasp at first, but with the right amount of ninja references, anything can be explained so someone can understand it. What’s my name fool To get a basic understanding of binding, check out this example. Function.bind. Javascript anonymous functions – Helephant.com. Anonymous functions are functions that are dynamically declared at runtime.

Javascript anonymous functions – Helephant.com

They’re called anonymous functions because they aren’t given a name in the same way as normal functions. Anonymous functions are declared using the function operator instead of the function declaration. You can use the function operator to create a new function wherever it’s valid to put an expression. Ruminations about the performance of anonymous functions in naive Javascript implementations. Ruminations about the performance of anonymous functions in naive Javascript implementationsBlock-Structured Javascript (better known as the Module Idiom) looks like this: (function () { var something_or_other; // code elided return something_or_other; })() This creates a new, anonymous function with its own local scope.

Ruminations about the performance of anonymous functions in naive Javascript implementations

Whenever this code is execututed, the interpreter creates a function record in its memory. JavaScript Closures and the Module Pattern. One of the most widely used design patterns in JavaScript is the module pattern.

JavaScript Closures and the Module Pattern

The module pattern makes use of one of the nicer features of JavaScript – closures – in order to give you some control of the privacy of your methods so that third party applications cannot access private data or overwrite it. In this post I'll teach you what a closure is, how it works, and how to utilize it to implement the module pattern in your own JavaScript code. Javascript: Closures. Las closures o cerraduras son un tema bastante explicado en javascript, el problema es que es tan confuso que aún cuando entendamos el concepto dificilmente aprovechamos su potencial en nuestros programas.Veamos la defininición.Una Closure es una función que es evaluada en un entorno conteniendo una o más variables dependientes de otro entorno.Como vemos la definición no hace más que contribuir a la confusión.Veamoslo así.En Javascript podemos definir una función en cualquier momento, inclusive dentro de la definición de otra función.veamos una funcion para encontrar todos los numeros pares entre 2 numeros. function numerosPares(Desde,Hasta){ function esPar(Num){ if(Num%2==0){ return true; }else{ return false; } //o, lo que es lo mismo //return !

Javascript: Closures

Num%2; } var pares = []; for (var i=Desde;i< Hasta;i++){ if(esPar(i)){ pares.push(i); } } return pares;} Constantly Changing: Undeclared, Undefined, Null in JavaScript. So, a coworker of mine run into a situation recently where they were testing for an expression in JavaScript as: if(obj.prop !

Constantly Changing: Undeclared, Undefined, Null in JavaScript

= null && obj.prop.subprop > 0) ... This basically guards you against dereferencing "subprop" if "obj.prop" is itself undefined or null. They were running into a situation where the first predicate would pass, and the second would fail. However, "obj.prop" always printed "undefined". Ouch. Detecting an undefined object property in JavaScript. How to check a not defined variable in javascript. Instant Documentation Search. Date Formatting And Format Validation Functions.