Issue

01

A DIFFERENT TYPE OF AGENCY

As a collective, The Factory Interactive is fueled by a passion for developing enduring messages conceived through a marriage of design and technology. At the core, we are explorers of possibility and architects of memory. We create rich immersive experiences that increase message retention and reward the audience. Our mission: give personality to products, resulting in a stronger, more effective brand.

Contact Us
305.752.9400
info@thefactoryi.com

The Factory Interactive’s eZine into the world of Online Marketing & Design Interaction.

Cleaner Javascript Design By Briam Rodriguez

Cleaner Javascript Design By Leveraging Closures and the “Function as Object” design pattern

Intro
Javascript is a flexible, object oriented, language which is usually dismissed as a toy language for being too simplistic, or for lacking sufficient features with which to develop applications. Part of this dismissive attitude stems from a misunderstanding of Javascript’s greatest strength, its flexibility.

It’s so flexible in fact, that it leads to spaghetti code more often than not because the developer approaches javascript development without a solid design pattern in mind. Most javascript scripts that I’ve seen (and some of my own, I must admit) have turned out to be horrible tangled messes of asynchronous callbacks (functions which are scheduled to be run at an unspecified future time) to which even more cruft is added as application requirements are added or removed. Essentially, most of these “one-off” scripts contain the same trademark flaw: they fail to model their entities appropriately, leading to inconsistencies all across the board.

There are three solutions to these recurring problems, namely the judicious use of closures, the “Function as Object” design pattern, and the proper modeling of program entities.

Functions As Objects
Many languages have special constructs to define an object, viz. keywords relegated to that specific use. Javascript has no such constructs, though it has the capability to define objects, and it approaches the task in an odd but satisfactory manner.
It turns out that functions (as in most of the better languages) are actually first-class objects themselves. This means that they can be assigned, transferred, have properties added to them dynamically, can (usually) be created anonymously, and can reference themselves (amongst other interesting properties).

We take advantage of the fact that javascript can define anonymous functions inline and use it towards our “Function as Object” pattern through the use of the “new” keyword. The “new” keyword takes the object given after it and creates a reference to a new, separate copy of the defined object.

Let us examine this example (a record for a person), assuming it is in the global scope:

    // define a new person object

    var Person = new function() {
    };

This would create a new object “Person” in the global application namespace, with no properties or methods. Right now this is of no practical use, because the object contains no data (properties), and no operations (methods) can be performed upon it. Before we can assign it properties though, the Person object needs to have a reference to itself.

Speaking of properties, how can we assign any if we do not know where they are to be assigned?

We could use the global name “Person” to assign the object attributes, but what happens if we change the object’s name to “HumanBeing”? That would be out of the question since our references would break, and each would need to be individually changed.
We could use the the “this” keyword which references the current call-chain, but that would break if one of our methods is used as a callback. (This is due to the fact that the meaning of the “this” keyword depends on how a function was called.) Or, we could use something called a closure; and pass a reference around subtly and make our lives easier.

I will opt for the latter.

Closures
You may have heard of the term closure before; but what is it and why is it so useful? A closure is simply a function which encapsulates a reference to its containing environment. Absolutely everything… container, properties, methods. the whole kit is passed along. This in itself is not an exciting thing, but when used carefully it can do some pretty amazing things like assist in generating customized functions, or in our case, encapsulate a reference to our parent object. Let’s see how we can use a closure to provide a consistent access point into our object, independent of caller.

Take a look at the our Person object:

    var Person = new function() {
        var self = this;

        self.first_name = "John";
        self.last_name = "Doe";
        self.birth_date = "10/24/1900";

        // notice the use of anonymous "lambda" functions to assign methods to the object

        self.get_full_name = function() {
            return(self.first_name + " " + self.last_name);
            };
        };

What do you see? When we execute the code we get:

    js> Person.get_full_name()
    John Doe


Properly Modelling Your Entities

Using this design pattern we can model our entities and save time and effort, all while beating more complex languages to the punch!

What we have done is taken the current value of the “this” keyword, and caused a global reference to be passed into all of Person’s methods. This might seem similar to you if you’ve ever programmed Python, for example, where the self keyword is part of all objects and used in exactly the same way. This particular design pattern, of “Function as Object” + closures is something which makes programming in javascript hassle free and makes things work as expected. You can even call Person’s methods in javascript callbacks (from jQuery for example) and as long as you reference self, you will not have any issues as to when the “this” keyword really is “this” or “that” or something totally different altogether!

Consider this example code:

    // Notice how I omit the "new" keyword before the function declaration
    // in order to create a class definition instead of a class instance.
    // The "new" keyword is usually used to create instances of a class
    // defined in this way.

    var PersonClass = function(first_name, last_name, date_of_birth) {
        var self = this;

        self.first_name = first_name;
        self.last_name = last_name;
        self.date_of_birth = date_of_birth;

        self.get_full_name = function() {
            return(self.first_name + " " + self.last_name);
            };
        };

    var John = new PersonClass("John", "Doe", "10/24/1900");
    var Jenny = new PersonClass("Jenny", "Doe", "10/24/1900");

    js> John.get_full_name()
    John Doe

    js> Jenny.get_full_name()
    Jenny Doe

It doesn’t matter whether get_full_name is invoked directly or indirectly via callback because the reference to the internal object is passed in via a closure. Now that is object orientation that could rival even the best of OOP languages!

Conclusion
Use of the “Function as Object” design pattern, coupled with usage of the self reference/closure idiom is a powerful tool to make javascript look and feel like the big boys of programming, whilst keeping the simple flexible design of the javascript language available at your fingertips. It removes the inconsistencies encountered when calling methods or accessing parameters via call-back, isolates the way you access data from the way that methods are called (function call chain), encapsulates your data, and is just plain overall fun!

Post to Twitter


Filed under: Uncategorized — @ 2:00 pm

Comments (0)


Manufacturing Lightning in a Bottle By josh

On Wednesday of this week The Factory Interactive held a seminar Social Media for Small Business to provide some background information on the major players in the social media game and give our attendees some solid tips on how to leverage them.  Throughout Jason’s (@jasoninasi) presentation it became more and more clear that one of the most dependable methods for gaining rapid traction in social media is timeliness.

Let’s take a a quick look back at some of the examples presented during the seminar:

Kogi BBQ (@kogibbq) - Kogi uses Twitter to announce the locations for their lunch trucks on a daily basis and while only following 1,700+ users themselves they have amassed a following of their own of almost 68,000 hungry lunch goers!

Kogi, and other daily information providers like Woot (@woot) and Dell (@DellOutlet) are leveraging routine, informative and short-shelf life tweets in order to create urgency in their followers thereby maximizing the value of their tweets.

When we launched the We Want Wade (#wewantwade) campaign in May several factors converged to provide the “perfect storm” of social media.  Wade’s contract was ending, anxiety amongst his fans was increasing (would he stay or would he go?) and interest in the NBA was peaking during the playoffs. We were able to successfully leverage these conditions in order to generate a frenzy of interest and participation immediately upon the campaign’s launch.

So, how can the average business owner use this knowledge to gain a leg up on the competition, drive more leads in or gain more followers?

First, you have to remember to keep that signal to noise ratio low.  You should always have something worthwhile and on-topic to say.  If you don’t have anything to contribute, your silence will be more appreciated than a dry, over-extended sales pitch.

Second, take advantage of the information available at Google Trends. Nothing will grab new audience members or reinforce your relationship with existing followers more than a timely tweet to your recently written blog post covering some breaking news, industry trend or burgeoning meme.

Finally, if the situation is applicable, you can turn short-duration promotions into big money.  Consider a regular publishing frequency combined with quickly expiring valuable offers.

Good Luck!

Post to Twitter


Filed under: Uncategorized — @ 11:41 am

Comments (0)


All The World’s A Twitter – How’s Your Business Twitt’etiquette. By jason

With the explosive growth of Twitter over the last few months (worldwide visitors to Twitter.com increased 95 % in the month of March to 19.1 million) many companies are standing on the sidelines wondering how to get started and are plagued with questions.  What’s a tweet;  do I need to follow everyone; will @Oprah show me some love; what the heck is #followfriday ?  Are you riding the 140 character wave or being swept out by a sea of change. Here are a few tips to help you make some sense of the Twitterverse and Tweet with confidence.

1. Complete your Bio.

Most new Twitter users do not fill out the small but important section that says a bit about who they are.  Other users hover over your icon to get a glimpse into your Twitter profile & this bio is a great way to entice them into checking you out.  If you have a website or blog include it as this is a great way to increase traffic to it and it can help with SEO.

2. The secret is in the sauce: Be valuable.

Don’t broadcast – engage.  Twitter is great for two way communication, so remember that fact when you Tweet. No one wants to hear just your sales pitch over & over. Be cognizant of that fact & share useful information via your Tweets. Don’t be schizophrenic. If you are trying to be an expert on a subject, then stick to it as much as possible. A few personal bits of info are good but should not overpower the expertise you want to be known for.  users may also Retweet your posts so make sure you are being presented in a favorable light (save the vegas story for another platform). In other words limit your signal to Noise ratio and you will quickly amass new followers.

3. Don’t forget to use #hashtags/
Hashtags are a community-driven convention for adding additional context and metadata to your tweets.  You create a hashtag simply by prefixing a word with a hash symbol: #hashtag. Hashtags were developed as a means to create “groupings” on Twitter, without having to change the basic service.  Hashtags.org provides real-time tracking of Twitter hashtags. Opt-in by following @hashtags to have your hashtags tracked.  (source: http://twitter.pbwiki.com/Hashtags).

4.  You don’t need to follow everyone.
Be strategic and follow those people that are likely to follow you back or share similar interests. This way you are communicating  to an eager audience of like minded individuals.  Exceptions to the rule: these 237 Twitter users that will follow you back http://tinyurl.com/cm68vr.

5.  No thank you Mr. Roboto.
Avoid applications that auto respond when people follow you. They can feel fake & you’ll miss opportunities to engage in conversation with new followers. There are many Twitter users that will block you for sending auto-responders, so be wary of this fact and use at your own risk.

6.  Learn the Twitt’etiquette.
There are a number of unspoken rules on Twitter.  Learn about them before you make newbie mistakes. For example, give credit to users when you ReTweet, (RT) don’t hijack someone else’s message as your own, use Direct messages (DM) for personal conversations instead of posting to the user’s publicly viewable account.  Here is a list of Twitter terms to get you started (http://twictionary.pbwiki.com/)

7. Make your messages easy to Retweet.

A Retweet is when someone takes your Twitter message and tweets that same message to all followers in their own Twitter network. Retweeting allows your message to spread throughout the Twittersphere. This is great for blogs, articles etc. so keep your tweets short & invite users to retweet your post (a simple “please retweet” works well).  If you use WordPress for your blog, add the TweetThis WordPress plugin. It places a “Tweet this” link at the end of your articles so readers can post to their network of followers.

Our next two posts will continue the Twitter theme;  we will show you 10 tools that help you make the most of Twitter discuss the best ways to build brand credibility via social media, see you soon.

Post to Twitter


Filed under: Uncategorized — Tags: , , , , , , , — @ 11:22 am

Comments (0)


History of the Internet By Ashley

History of Internet

“History of the internet” is an animated documentary explaining the inventions from time-sharing to filesharing, from Arpanet to Internet. The history is told using the PICOL icons on picol.org , which are available for download soon. On blog.picol.org you can get news about this project.


Post to Twitter


Filed under: Uncategorized — Tags: , , , — @ 2:02 pm

Comments (0)


Paid-For-Content?? The Great Debate (of the day, at least) By Ashley

There has been a lot of buzz lately about whether media organizations should start to charge to view their content. And is the model that will save these companies from going under?

I have two trains of thought on this:

Thought Process Numero Uno: I think back to pre-iTunes days when I would use programs like LimeWire to download ALL of my music for free. The days of buying CD’s were long over for me. Then iTunes came along, and gasssp, they were going to charge for their music. I won’t lie… I boycotted for as long as possible. But then I saw the light… it was SO much easier and convenient to download off of iTunes. I always knew what I was getting and that the quality would be perfect; and on top of it all I was supporting the artists I enjoy.

I think it’s very possible that web-users will ultimately do the same thing with getting their news/videos. Most of us will be rebellious at first but soon enough we will see the light…and the value in getting quality content, and supporting the staff that work so hard to bring us this content. Of course, this all depends on how reasonably priced it will be. If companies are competing with each other for eyeballs, I imagine it will have to be pretty low cost.

Thought Process Numero Dos: Newspapers/Broadcasters will  be shooting themselves in the foot if they adapt a paid content business model. Why? Because there will always be ways to find similar, if not the same, content for free so we will never want to pay. Furthermore, according to a Knowledge Networks poll, 80% of online network TV viewers would prefer to view ads in exchange for unpaid video content, up from 67% in 2006. So clearly users will go to some type of extent to avoid paying fees for content. Can the same methodology be applied to a “print” ad before reading any articles? Seems like a plausible scenario.

The Associated Press unveiled rate cuts on Monday to help member newspapers reeling from declining advertising revenue and said it would also sue websites that use its members’ articles without permission. They have been the first to announce such an aggressive plan. I am very curious to see how this plays out, but I know one thing is for sure… I have read a lot of articles about their announcement this week and none of it seems to be positive. Let the foot shooting begin…???

Post to Twitter


Filed under: Uncategorized — Tags: , , , , , , , — @ 10:32 am

Comments (1)


Older Posts »

Subscribe to our feed

subscribe

Search

Learn More

Effective SEO marketing requires meticulous analysis of keywords, link relationships, information architecture and the site's visual design.
Is your web solution working for your business? Contact a digital marketing expert at The Factory Interactive to find the answer.