Devleague 5/2

Covering module patterns…I think this has been one of the most confusing moments so far. (I have a feeling I will be saying that a lot.) But I think I am slowly understanding the structure of it. Sort of. Kinda. Ish.

First of, let’s start of with concepts I think I understand…

This is basically referring to the placement where a variables and functions are branched under. We use the terms parent and child (or even grandparent/grandchild) to class the relationship between two elements. Children can use variables from their parents, but parents cannot use variables within their children. Likewise, children of the same parent on the same level of branch cannot share variables. The idea is that you can always pull from the larger scope, never the other way around.

This function is awesome. Paired with an array or (object?), it will rearrange the elements of the array in alphabetical and numerical order. There’s ways to reverse the sort order as well, apparently. Nice.

Identifying the index of an element
Ray: Hey, I’m looking for the indexOf (“Waldo”).
JS: He’s identified as 4 in the array.
Thanks, JS!

NaN & IsNaN
NaN is a tricky bastard.
NaN == NaN //false. wat.
NaN === NaN // false. wat.

Meet our new friend, isNaN. He will tell you if NaN is a NaN.
isNaN(NaN); // true
isNaN(undefined); // true
isNaN({}); // true

isNaN(true); // false
isNaN(null); // false
isNaN(37); // false
isNaN(“string”) //false

IIFE (Immediately Invoked Function Expression)
Is what it says it does. Immediately invokes the function. Once.

(function name(){ //do stuff

Sometimes you want to close a set of code so it can’t be touched. This dips into the idea of scopes. If parts of a code is within a function, things on the outside cannot use things on the inside.

Revealing Module Pattern
Getters..Setters..Public variables…
Okay. So understanding module patterns, I believe is this:
When you set an encapsulation on code so it’s contents is private, but then you want to use some of those variables or functions in that closure, you set up a revealing module pattern by returning an object that can hold a plethora of valuable information. That way you can use the function as normal, but people can’t mess with the contents in that function.


var myRevealingModule = (function () {
var privateVar = “Ben Cherry”,
publicVar = “Hey there!”;
function privateFunction() {
console.log( “Name:” + privateVar );
function publicSetName( strName ) {
privateVar = strName;
function publicGetName() {

// Reveal public pointers to private functions and properties
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
myRevealingModule.setName( “Paul Kinlan” );

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.