Testable JavaScript in Action (Hands-On Workshop)
Do you like the idea of Test-Driven Development (TDD) for the web, but don’t know where to start? Do you think clean code is awesome,… Read More »Testable JavaScript in Action (Hands-On Workshop)
Do you like the idea of Test-Driven Development (TDD) for the web, but don’t know where to start? Do you think clean code is awesome,… Read More »Testable JavaScript in Action (Hands-On Workshop)
In the last 20 years, software developers have written billions of lines of JavaScript code. Believe it or not, some design patterns have emerged! If… Read More »Stop Re-Inventing the Wheel: JavaScript Design Patterns
Are you promiscuous with your JavaScript code? Strewing functions and commands here and there? Nested closures, manual obfuscation, global functions… all of these ‘natural’ JS… Read More »Clean JavaScript: Tame the Unicorn
If you can answer these questions, you may not need this presentation: If everything is an object, why does 2.toString() throw an error? What is… Read More »JavaScript You Never Knew Existed, But Cannot Live Without
JavaScript strict mode tells the interpreter to be more particular about what is allowed. In general terms, strict mode makes your code a little safer by turning some bad coding practices into exceptions.
For existing code, this is good and bad. It’s good, because it helps you find some potential bugs, like accidental globals. It’s bad because code that used to work, might now be broken.
Here’s the kicker: for new code, it is almost always good.
Read More »Strict Mode in JavaScript
Some of the most common complaints about JavaScript come from its dynamic, mutable nature. You can modify nearly any member of any object and even delete some built-in ones! This enables web developers to improve cross-browser compatibility of their sites while maintaining code readability with a technique called poly-filling. On the other hand, it also allows developers to modify built-in behavior (called “monkey-patching”), sometimes causing side-effects or bugs that are difficult to troubleshoot.
Starting in ECMAScript 5, new mechanisms have been defined to give you (the developer) the ability to restrict what can be done to your object members. You can read the standard here. I did. Twice.
Read More »Property Descriptors in JavaScript
Because JavaScript uses prototype-based inheritance, there is no keyword to define a member as “private” or “protected”. Either the object has a member, or it doesn’t, and you can access that member from anywhere you can access the object. Do not despair! There is a way to implement private variables… using another feature of the language: closures!
Closures are fairly simple, but frequently misunderstood. What you need to know for now, is that a closure allows you to reference an outer variable from within a function, even when the function is called from another context.
This will make more sense when you see some code.Read More »Private Variables in JavaScript
Native JavaScript inheritance is prototypical. For one, this means that you don’t inherit from classes, you inherit from objects. You don’t define classes and instantiate them. Instead, you create objects and use them as a “prototype” or “base” for your own object instances.
In JavaScript, this is facilitated with the mechanisms called “prototype” and “constructor”.
Read More »Inheritance in JavaScript
JavaScript is one of the most widely used and misunderstood programming languages in existence. Nearly every personal computer and mobile device in the world can interpret it, and nearly every developer (and non-developer) that has made a website has written it, some without knowing it!
If you call yourself a JavaScript developer, then here are some things that the language can do that you need to know about, whether you use them or not! If you are using them, then you should understand them!
Read More »Useful JavaScript Features You Aren’t Using
As an anti-pattern, input kludge describes a poor user interface that either rejects or incorrectly handles valid input.
The most obvious code smell that may point to this pattern is ad-hoc input validation routines.
Look for:
$('form').on('submit', function(event) { if (!(/^.*@.*\.(com|edu|net|org)$/g.exec($('#email').val()))) { alert('You must enter a valid email address.'); return false; } })