Dan Martensen

Software Engineering

Page 2

What’s “new” in JavaScript?

Few syntactic features highlight JavaScript’s object oriented nature more than the new operator. Many of us have been using it for years but do we really know what it does? In languages like Java it allocates memory for an instance object, invokes a constructor function, and returns a reference to the object. And the same holds for JavaScript. But with the language’s use of first class functions and prototypal inheritance, there’s much more to new.

In this post I’ll cover the relationship between function instance objects, prototype objects and instance objects, what happens when new invokes functions, and which functions can be used as constructors.

Function Instances & Prototypes

Before we explore how new works let’s quickly review JavaScript functions. When a function is defined a function instance object is created under the hood, having a prototype property that...

Continue reading →

The Anatomy of a JavaScript Function

Functions in JavaScript are like classes to Java. They’re the fundamental modular unit: the cell in life, the note in music, the word in language, the funky chicken in dance. JavaScript functions are full fledged objects, often called first-class objects[1], having properties and methods, mutable values, and dynamic memory. Douglas Crockford, one of the early gurus and longtime critic of the language wrote[2]:

The best thing about JavaScript is its implementation of functions.

In this post I cover the qualities of functions as objects, how function objects are created, the difference between constructor, prototype, and instance objects, how the new operator works, and useful properties of functions.

First Class Objects

Functions have the same capabilities as other objects. So it’s no secret they can be:

passed as arguments

function a() { ... }
function b(a) { ... }


Continue reading →

Type Checking Techniques in JavaScript Part 2 of 2

To get the most out of this article you’ll want a solid grasp of JavaScript’s data types including built-in, custom, and host objects. If you need a little refresher see Part 1.

As front-end developers today are working with larger code bases, more 3rd party frameworks, and in teams, using effective type checking techniques is critical to writing bug free code. And you know how it goes, right? Less bugs means less Jira tickets reopened, less QA regressions, less work for project leads, and happier managers.

But the JavaScript language seems to be working against us. With it’s untyped var keyword, absence of typed parameters in function signatures, and implicit type conversions, combined with the lack of a unified getType() function, our need for reliable approaches is only increased.

In this article I’ll cover three effective techniques for type checking and identify each of...

Continue reading →

Type Checking Techniques in JavaScript: Part 1 of 2

One of the early milestones in grocking any programming language is knowing how to use its data types. Should be easy for a small scripting language like JavaScript, right? And yet because of the elusive var keyword, implicit type conversion system, and dubious type checking tools, working with types can be a confusing task for even experienced developers.

Before we cover type checking in detail we must thoroughly review data types in JavaScript, the purpose of Part 1. In this short post I’ll quickly cover the conceptual differences between primitive and object types, identify the types, and compare the built-in, custom, and host objects. Because this topic has been so muddied over the years I’m going to profusely site sources.

Primitives vs Objects

Like many languages, JavaScript has both primitive and object types. Let’s explore the fundamental differences between these two:


Continue reading →

About Blog

This blog’s about my adventures as a full stack software engineer. I hope you find something useful here.

After earning a Computer Science degree a few years back, I’m enjoying a career as a software engineer in Boise, ID since May 2014.

If you have any questions or comments about my posts, feel free to reach out on LinkedIn.

Avator: Foot bridge on Mount Rainier, Washington USA

View →