PLAY
VIDEO
READ TIME: 5
Article

Knowledge Share: Making that JavaScript Rich

Author

/
Justin Workman

TOPICS:

/Software & Product
/Web / CMS / Replatforming
/Mobile

What is a rich web application?

In short a web application is a piece of software hosted somewhere on the Internet. Compared to a typical informational website, a web application is a program that simplifies a process for a user. Much like web services, a web application is data driven, providing many different user flow paths.

So, where does JavaScript come into play with all of this?

As technology improves over time, the experiences get even richer. JavaScript is a great way to improve the overall experience of any web interface by creating a more smooth experience for the user.

How does the word “rich” apply to JavaScript?

We have access to many different JavaScript frameworks now, such as jQuery. Most JavaScript frameworks can make a developer’s life a lot easier, but not necessarily for other developers that may want to jump on the project after you.

Well, what is the problem?

As you all know JavaScript is what’s called a prototyped language. By being a loosely typed language, it gives developers a lot of power over speedy development, but herein lies its downfall, as well. With great power comes great responsibility—just because the language allows you to, doesn’t really mean you should.As a web developer, myself, I see a lot of JavaScript that was typed in a top-to-bottom approach. Since JavaScript is an event-driven language, you have to create callback functions to handle events. Most other client-side languages are the same way. JavaScript’s prototyped structure makes it way too tempting to have nested callbacks. If you look at it from another developer’s perspective, all they see is a big chunk of code that looks like the letter “v” flipped on its side—like this “>.” Nesting functions need to be used very carefully.Since the invention of SmallTalk, developers have had access to a design pattern called object-oriented programming. So, in short, rich JavaScript should really mean “strict object-oriented JavaScript.”

How we can write strict object-oriented JavaScript?

Well, first I want to explain how it can help solve JavaScript’s loosely typed issues. In general, OOP has been one of the most adapted patterns in development. OOP saves developers from writing redundant code. In most cases, it also gives an application a layer of organization, which improves maintainability.If we are talking about large-scale web applications, then we must stick to a very strict JavaScript OOP standard. Large applications tend to leak money through maintainability if programed in a loose fashion, but when coded in a modular fashion using objects, the application is positioned for success from the start. It will also lead to more profit later, when maintaining.

How do we apply OOP standards to JavaScript?

Well believe it or not, JavaScript is pretty much OOP out of the box. The only difference that we are applying is the way we think about it. Let’s create some classes in JavaScript that we can later turn into objects.var Person = function() { //This is the code of a person}We created a class called “Person.” In JavaScript, we define a class through a function. The function can also be referred to as the “constructor” of the class. A class is really just a function that contains code to set up an object.Now we will get to the good OOP patterns. Normally, in any standard object oriented language, you will encounter private, protected, and public properties of an object. JavaScript doesn’t have an idea of what protected means, but we can create private and public properties, and methods in our object.Below we will create a private property that only our object can see, as well as a public property that can be seen both in and outside our object. We will create the internal and external parts of a human.var Person = function() { //This is the code of a person // Private properties that only person can control
var heart = new Heart();
var brain = new Brain();
var stomach = new Stomach(); // Public properties that anybody can see
this.leftLeg = new Leg();
this.rightLeg = new Leg();}As you can see, if you want to make something public, we just add “this” in front of the name. It will add it to the scope of the Person object. If we place a “var” in front of the name, then the scope of the variable is locked inside the Person object.Now we need to add functionality to the Person object so that we can manipulate its properties. In the example, we are assuming we have all of the other objects defined somewhere else. We will make a public method that we can access from anywhere, and a private method that only the Person object can call.var Person = function() { //This is the code of a person // Private properties that only person can control
var heart = new Heart();
var brain = new Brain();
var stomach = new Stomach(); // Public properties that anybody can see
this.leftLeg = new Leg();
this.rightLeg = new Leg(); this.run = function() { this.leftLeg.stepForward(
rightLeg.stepForward
); //Heart rate increases
heart.increaseRate(); } this.eat = function() { stomach.digest(
new Salad() // Foot to eat
); } //This will be executed when hungry
var onHungryFeeling = function() { this.eat(); } // Bind to the Brain's hungry feeling
brain.onFeeling(
brain.HUNGRY_FEELING, //Feeling type
onHungryFeeling //Execute onHungryFeeling callback
);}We declared a private method called “onHungryFeeling” using the keyword “var.” This will be the main delegated callback that will handle the Brain’s hungry feeling. We also made some public methods like “eat” and “run.” These methods can be executed anywhere outside of Person.These are the basic principles of JavaScript OOP. The level of abstraction in the example I showed might be a little overboard, but it’s all in an effort to teach the basic principles of OOP JavaScript. In a real-world scenario, you can use frameworks like Backbone.js. These are great frameworks, because of their object-oriented approach to JavaScript.All in all, OOP can dramatically improve maintainability in your code, as well as reusable code. I often find myself using a combination of jQuery factory objects with actual custom JavaScript classes. It is important to have a balanced approach to loosely typed languages. Remember: Just because you can write loosely with JavaScript, doesn’t mean you should.

How Brands Can Leverage AI to Enhance Customer Experience

Reframing the Web: Your Site Isn’t a Destination. It’s an Experience Platform.

Team Highlight: Cassie Tangney

Outlandish Optimism at PRPL | International Design Day 2025

Unlocking the Power of Content Organization: Insights for Museums and Beyond

Team Highlight: Jeff Katipunan

PRPL and Museums: A Partnership Built on Creativity and Impact

Team Highlight: Maria Szlosek

Team Highlight: Vic Cao

Team Highlight: Jenn Hunter

Driving Innovation in Design Management: Strategies for Fostering Creativity

Team Highlight: Anibal Cruz

Mastering Leadership with SLANT: A Principle for Effective Engagement By Bobby Jones

Breaking Boundaries With Augmented Reality

Navigating the Replatforming Process: A Comprehensive Guide for a Smooth Transition

Team Highlight: April Domingo

Team Highlight: Chris Sell

Agency Partnerships: What’s In It For You

Upgrading from Drupal 9 to Drupal 10: A Step-By-Step Guide

Team Highlight: Francesca Parker

Navigating the Replatforming Process: A Comprehensive Guide for a Smooth Transition

Purple, Rock, Scissors Wins Web3 Awards, Including Two Golds

Purple, Rock, Scissors Wins Six ADDY® Awards, including Best of Show

Transforming User Experience through Augmented Reality

Purple, Rock, Scissors Tops Orlando Business Journal's Book of Lists

Transforming the Patient Experience: Purple, Rock, Scissors' Collaborative Partnership With AdventHealth

State of the Art: How AI is Influencing Design

8 Ways to Increase Museum Visits with Digital Experiences

Functional vs. Class-Based React

10 Components Your Museum Website Needs to Succeed

Staff Augmentation: Utilizing Digital Creative Agencies for Your Business Needs

Technical Insights: Integrating Your Health App with Epic EHR/EMR Systems

Remote work? Hybrid ? We prefer flexible.

Optimization Primed: How AI is Making Businesses More Efficient

Fit to Print: How AI is Improving Business Writing

Best Museum Websites to Inspire Your Next Redesign

PRPL Summit Weekend

Cam's Tips for Working Remote

Google Update: Core Web Vitals

CX Essentials: What the Customer Experience Can Teach You About Being a Better Brand

PRPL Playlist: Creative as Folk

Google Update: Mobile-First-Indexing for the Whole Web, and What it Means for Your Website & Business

Student Design Society: Apply for Our Summer 2019 Internship

PRPL Playlist: Hits from the Crypt

PRPL Playlist: Back 2 School

PRPL Playlist: 1nn0vate

Scientific Storytelling at the Field Museum

What To Do When a Project Is on Hold

Hard Rock + PRPL

What Organization Means to a Creative Person

PRPL Playlist: Artificial Inchilligence

PRPL Playlist: BBQ Bangers

Vote PRPL in SXSW's PanelPicker!

A Comprehensive Beginner’s Guide to Automating with Ansible

Launched: Lux Capital

We've Moved to Medium!

Spotlight: Chris Reath

Content Before Design: The Fall of Lorem Ipsum

PRPL Playlist

3-Pointers: Project Manager Advice

Spotlight: Rad Kalaf

Launched: LMG

What the Internet's New TLS 1.2 Encryption Standards Mean for You. Yes, You.

Let’s Talk About SaaS, Baby.

NASA’s IDEAS Project Update: Phase 1

Thinking and Designing with Components

3-Pointers: Stellar Style Guides

Launched: Stetson University

Put on Those Beer Goggles!

Polymer Web Components Tutorial

Battle of the Jams

What’s My Title, Again? A Case for Generalists in the Web Industry

3-Pointers: Boost Tweet Engagement

Myers Briggs for Businesses

More iBeacons, Please!

Launched: 3Cinteractive

Spotlight: Katie Bartlett

Mo' Data, Less Problems: Finding Value in Big Data

What the Heck is an Agency Partner?

Briefs: Renee on Why Devs Are Cranky

How We Scrapped Time Sheets

5 Reasons Why the Office Phone is Dead

Launched: Adventist University of Health Sciences

Why Changing Careers is Like Changing Your Pants

How to Build an App Using Meteor JS

Spotlight: Adam Bullinger

Experimenting with Meteor Development

Webinar: A Field Guide to Interaction Design

Landed: NASA Partnership

Gifn: Rise of the GIF Photobooth

Briefs: Mike on Value-based Billing & Profit

iSummit Conference & Ticket Giveaway

Briefs: Adam & Renee on Magento

Chasing Perfect Weather with Mullen & CSX

Developing With Vagrant Flavors

Need Some Space? Book Ours.

Spotlight: Alex King

Designer Merch Collection

10 Reasons to Offer Flexible Work Hours

Google I/O Fanboy Duel

Close

TEAM MEMBER

ABOUT

Justin Workman

ABOUT

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.