Let's Make a Framework: Feedback

2010-08-19 00:00:00 +0100 by Alex R. Young

Welcome to part 26 of Let's Make a Framework, the ongoing series about
building a JavaScript framework.

If you haven't been following along, these articles are tagged with
lmaf. The project we're creating is called Turing.

I received some feedback last week about Turing -- very useful and
interesting points that I thought followers of the series would enjoy.

Alias Library Eval Usage

Øyvind Sean Kinsey commented on one of my commits to say that he thought the way Turing creates a global alias
was unnecessary. My code looked like this:

eval(turing.alias + ' = turing.aliasFramework()');

The reason I did this was so turing.alias would expand to
the variable name. This was so people using Turing could alias it to a
short name, like jQuery's \$.

turing.core stores a reference to the global context, which
is generally window. As I like to write unit tests outside
a browser I pass in an object rather than relying on
window. Because the old version of turing.core
didn't expose this global, I used eval to create a similar

Taking on board Øyvind's feedback, I've added a method called
exportAlias to the core library, and changed
eval to:

turing.exportAlias(turing.alias, turing.aliasFramework);

A lot of libraries and frameworks set properties on window
in a similar way.

DOM Ready Not Required

After all the work I put into creating a DOM ready implementation, it
wasn't really required! It's possible to insert