Home Posts tagged "objects"
formats

JavaScript Callback Functions – The Absolute Basics

in Functions.

Callbacks are a critical tool for properly handling asynchronous events in JavaScript. Timing is one of the most difficult techniques to master in JavaScript. At first, many look to the setTimeout() method to address the asynchronous nature of JavaScript. But that is most often not the best approach. The concept of a callback function is

(More)…

formats

jQuery Plugin Authoring – The Absolute Basics – Part II

in jQuery.

Once you have jQuery plugin basics down, it’s time to implement some best practices In the previous post “jQuery Plugin Authoring – The Absolute Basics – Part I”, we to a detailed look at the architecture of a jQuery plugin. Now that you understand the building blocks, let’s discuss a few best practices. These techniques

(More)…

formats

jQuery Plugin Authoring – The Absolute Basics – Part I

in jQuery.

You know a little jQuery, you have used a few jQuery plugins, and now you want to write your own jQuery plugin. Don’t worry, it’s no big deal. In fact it’s fun. If you have been putting off authoring your first jQuery plugin, it’s time to wrap a bandana around your head, fire up “The

(More)…

formats

What is the Difference Between Scope and Context in JavaScript?

In JavaScript, scope and context are not the same thing, and you should understand the difference between them. Fortunately, the answer is short and simple. When interviewing front-end developers, I usually try to include a question about Scope and Context in JavaScript. I always ask what the difference is. The answers I get often surprise

(More)…

formats

Making Your JavaScript Code Easier to Understand: Object Literals

When it comes to organizing your object literals, there are multiple approaches you can take Object Literals are a very useful feature of JavaScript. They allow you to easily build structures of data or functionality (or both mixed together), without too much fuss and drama. The syntax is simple and they make it easy to

(More)…

formats

JavaScript Closures – The Absolute Basics: Getters and Setters

The next step in mastering JavaScript closures is being able to “get” or “set” a private variable In Part I of this series: JavaScript Closures – The Absolute Basics, I discussed wrapping one function with another, which produces a closure. When that returned function is assigned to a variable, as long as that variable is

(More)…

formats

Understanding Context in JavaScript – Object Literals

Why is the word “this” so important in JavaScript? In the post: “Understanding Scope in JavaScript,” I covered the basics of how scope works when dealing with functions. Sometimes the words “scope” and “context” are used interchangeably, which only leads to confusion because they are not the same thing. In JavaScript, “context” refers to an

(More)…

formats

How to Create a JavaScript Object Literal

Learn how to quickly and easily create your first Object Literal, and give it properties and methods There seems to be a bit of mystery surrounding the subject of JavaScript Object Literals. It is actually a simple concept and it’s easy to get started. There is a great deal of depth to the subject, but

(More)…

formats

JavaScript Closures – The Absolute Basics

Demystifying this topic is one of the most important steps towards truly understanding the JavaScript language It is a little difficult to get your head around JavaScript closures without a basic understanding of scope. I will not attempt to tackle that subject in any kind of detail here. But let’s at least consider this thought: JavaScript

(More)…

formats

Associative Arrays in JavaScript

You may be finding conflicting information about associative arrays in JavaScript. Well, the answer is quite simple…. and then things start to get a little odd If you are frustrated because you have been getting different answers on this subject, I”ve got good news and bad news. The good news is, the answer is simple:

(More)…

formats

The JavaScript for…in statement – enumerating object properties

The JavaScript “for in” statement allows you to literally “loop” through all the properties of an object, without knowing ahead of time what the object will be or how many properties it will have One of the most over-looked and under-used tools in the JavaScript language is the “for in” statement. This statement allows you

(More)…

formats

JavaScript Interview Questions: Object-Oriented JavaScript

Object Properties and Methods In JavaScript, Objects have two things: properties and methods. Methods are simply properties that have a function assigned to them. var foo = { color : “red”, getColor : function(){ //make this function return foo.color //without using the word: “foo” } } Q: Given the above code, what line of JavaScript

(More)…

formats

What is the difference between an Object Literal and an Instance Object in JavaScript ?

Although a JavaScript object literal and a JavaScript instance object are both objects, they differ in their inherent nature and features Object Literals An object literal is “flat”. You create it, you add properties and methods to it, and all of those properties and methods are public. You can mutate any members of that object

(More)…

formats

Using an Immediate Function to Create a Global JavaScript Variable That Has Private Scope

Keeping the global namespace clean is a good idea. Immediate functions allow the JavaScript programmer to do so with a great deal of power In a previous post, we discussed the topic of the JavaScript Immediate Function. Let’s re-visit this topic with a focus on creating a private scope with which we can interact. Most

(More)…

formats

The JavaScript “for…in” Statement – Don’t Leave Home Without It

Objects in JavaScript are first class types that have become a critical component to modern front-end web development. The “for…in” statement allows you to fully examine any object at run-time Making objects, instantiating objects, and enjoying all the wonderful properties and methods that we baked into our objects is what advanced JavaScript is all about

(More)…

formats

How to return an object literal from a JavaScript constructor

While it is easy enough to create an object literal, there are cases in which you may want to return one from a constructor. When doing so, you return an object literal that has added value. Everyone knows that creating a JavaScript object literal is as simple as var foo = {}. No problem. We

(More)…

formats

How to Include a Function as a JavaScript Object Literal Member

JavaScript object literals can contain not only properties, but methods too Some may automatically think of a JavaScript object as a name / value pair scheme with flat members that are essentially just scalar values. Fortunately, this is not quite the case. An object literal can also include functions among its members. Those functions can

(More)…

formats

Immediate Functions in JavaScript – The Basics

Functions are a very powerful feature in JavaScript; they provide modularity and scope. The immediate function is an often overlooked feature of JavaScript that offers a heightened level of functionality. An immediate function is a function that executes as soon as it is defined. Creating an immediate function is simple: you add the open/close parentheses after

(More)…

formats

How to Create a Custom Object with Public and Private Members

By making a distinction between what members of your object will be accessible to the  outside world, you can enforce a much higher degree of control and avoid unpredictable behavior. In a previous post, I discussed how to create your own name-spaced JavaScript object. This is a highly recommended approach that keeps the global name space

(More)…

show
 
close