<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Typical Noise</title>
  <id>http://typicalnoise.com/feed.xml</id>
  <updated>2015-03-05T09:56:07.759000Z</updated>
  <link href="http://typicalnoise.com/" />
  <link href="http://typicalnoise.com/feed.xml" rel="self" />
  <generator>Werkzeug</generator>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">What I love about AngularJS - Part 1</title>
    <id>http://typicalnoise.com/post/what-i-love-about-angularjs-part-1</id>
    <updated>2015-03-05T09:55:58.793000Z</updated>
    <published>2014-02-09T03:59:06Z</published>
    <link href="http://typicalnoise.com/post/what-i-love-about-angularjs-part-1" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="angularjs" />
    <category term="software-design" />
    <content type="html">&lt;p&gt;I have been developing AngularJS applications for a several months now. I have really come to like the framework and this series of post will explain why. If you are looking for yet another tutorial on how to get started with AngularJS then this serious is not for you. Instead I intend to address a fundamental issue I have with the approach we have taken to writing software and how AngularJS has resolved my frustrations. &lt;/p&gt;
&lt;p&gt;There are a lot of client side frameworks available. They all provide developers with some form of MVC pattern. Most of them simply re-hash the same patterns we have seen in server side frameworks like Rails, Django, and similar. Granted, most of them do offer new capabilities like some for of 1-way or 2-way data binding. They all still fall short when it comes to solving a fundamental issue I have with the way we structure and build applications today.&lt;/p&gt;
&lt;p&gt;All of this frameworks a great, don’t get me wrong, but they all seem to focus on the MVC. It does not matter if the application is largely server side or client side. Take your typical Rails application. Everything will start out clean early on in your applications development. Your models are clean and small, the controllers are simple and you have no logic cluttering up your views. However, as the business goals evolve and more and more business logic is placed into your application that logic needs to go somewhere. &lt;/p&gt;
&lt;p&gt;Most likely the first place this logic will appear is in the Controller. As time goes by the Controller gets more and more complex and soon it’s a 1000+ line beast. This is how I’ve seen a lot of early Rails applications structured. Lucky for the community this was quickly recognized as a bad approach. So all the business rules where moved out of the Controllers, leaving them to focus only on coordinating the interaction between the models and the views.&lt;/p&gt;
&lt;p&gt;So where did that business logic end up? In the models. This is what coined the term “Skinny Controllers, Fat Models”. I argue that this logic does not belong in the model. A model shouldn’t know or care about the business rules defining how to transfer funds from one user’s bank account into another users bank account. A model should represent the data and that is it. &lt;/p&gt;
&lt;p&gt;The business logic is the heart and soul of your application. It’s the entire reason for your application to exist. It is your Use Cases. Controllers, Models, Views, these are all part of the framework you are using they are not your application. So why do we treat these constructs as first class citizens and struggle to find a home for our business rules within our chosen framework?&lt;/p&gt;
&lt;p&gt;AngularJS is a framework that solves this fundamental issue. Over the next few posts I will go into more detail about what makes AngularJS different and it how solves this problem.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Tmux Pro Tip</title>
    <id>http://typicalnoise.com/post/tmux-pro-tip-1</id>
    <updated>2015-03-05T09:55:59.069000Z</updated>
    <published>2013-07-03T17:50:01Z</published>
    <link href="http://typicalnoise.com/post/tmux-pro-tip-1" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <content type="html">&lt;p&gt;If you ever find that you've done something silly like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; bind -n o select-pane -R
 bind -n O select-pane -L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then reloaded your tmux config live. Now when ever you type o or O you're switching panes left and right. No problem easy fix just remove the -n&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; bind o select-pane -R
 bind O select-pane -L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now it works as intended, but wait. Tmux does not automatically unbind keys. So how do you get your Os back?&lt;/p&gt;
&lt;p&gt;Simply detach from the session and tell tmux to unbind them&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; C-a d # note I have my prefix bound to C-a
 tmux unbind o
 tmux unbind O
 tmux attach
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Prest-O!&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">I'm blogging with Postach.io</title>
    <id>http://typicalnoise.com/post/im-blogging-with-postach-io</id>
    <updated>2015-03-05T09:55:59.431000Z</updated>
    <published>2013-05-10T06:46:39Z</published>
    <link href="http://typicalnoise.com/post/im-blogging-with-postach-io" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <content type="html">&lt;p&gt;Since its so easy to create a new post, hopefully this means I will actually blog with some regularity again!&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Ultimate macvim git commit setup</title>
    <id>http://typicalnoise.com/post/ultimate-macvim-git-commit-setup</id>
    <updated>2015-03-05T09:55:59.689000Z</updated>
    <published>2012-01-06T17:50:00Z</published>
    <link href="http://typicalnoise.com/post/ultimate-macvim-git-commit-setup" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="vim" />
    <content type="html">&lt;p&gt;Took me a while to piece this together. There is a great tip in the macvim github wiki FAQ. Appending the following to your &lt;code&gt;~/.profile&lt;/code&gt; (or &lt;code&gt;~/.zshrc&lt;/code&gt;, or whatever)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;export EDITOR='mvim -f --nomru -c &quot;au VimLeave * !open -a Terminal&quot;'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That &lt;code&gt;--nomru&lt;/code&gt; switch tells vim not to add the commit message to the Most Recently Used file menu and the &lt;code&gt;-c&lt;/code&gt; switch tells macvim to return the focus to the Terminal app when it quits.&lt;/p&gt;
&lt;p&gt;This alone is quite nice, but soon enough you'll start to notice a rather annoying feature, that under normal circumstances is quite useful. If you stop editing a file and re-open the file for editing again Vim will remember the line you were last editing and return you to that line. This gets annoying with commit messages since it will often put your cursor somewhere down in the comments. There is a quick fix for this too though.&lt;/p&gt;
&lt;p&gt;You can either add this line to your directly to your &lt;code&gt;.vimrc&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or you can create a file called &lt;code&gt;~/.vim/ftplugin/gitcommit.vim&lt;/code&gt; and add the following to it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;call setpos('.', [0, 1, 1, 0])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now vim will always place the cursor on the first line of your git commit messages.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Best Keyboard Shortcut Ever!</title>
    <id>http://typicalnoise.com/post/best-keyboard-shortcut-ever</id>
    <updated>2015-03-05T09:55:59.889000Z</updated>
    <published>2009-08-26T04:38:00Z</published>
    <link href="http://typicalnoise.com/post/best-keyboard-shortcut-ever" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <content type="html">&lt;p&gt;After using Adium for years and years I finally discovered what I consider to be the best shortcut I've learned in a long long time.&lt;/p&gt;
&lt;p&gt;With Adium being the active window &lt;code&gt;command + n&lt;/code&gt; will let you type a contact name and opens a new message window to that contact!&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Super Simple Ruby Performance Tip</title>
    <id>http://typicalnoise.com/post/super-simple-ruby-performance-tip</id>
    <updated>2015-03-05T09:56:00.177000Z</updated>
    <published>2009-07-11T22:10:00Z</published>
    <link href="http://typicalnoise.com/post/super-simple-ruby-performance-tip" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="ruby" />
    <content type="html">&lt;p&gt;This tip is so simple it can be expressed with two characters, &lt;code&gt;{}&lt;/code&gt;, curly braces. I've encountered this issue twice now. Once with some code in a project I work on as part of my day job, and once in a map reduce project I was evaluating.&lt;/p&gt;
&lt;p&gt;As we all know the Ruby stdlib Logger class defines a bunch of useful logging methods (&lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;info&lt;/code&gt;, &lt;code&gt;warn&lt;/code&gt;, etc ) which take a string argument as the message to log. We can control which level of message is written to the log file quite easily, so that we only see the messages we care about appear in the log. This should be old news to any Rails or Ruby developer.&lt;/p&gt;
&lt;p&gt;These Logger methods also take a block argument. When a block is given, it's return value is used as the message for the log file.&lt;/p&gt;
&lt;p&gt;For instance:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;a href=&quot;http://logger.info&quot;&amp;gt;logger.info&amp;lt;/a&amp;gt; &quot;some message&quot;
&amp;lt;a href=&quot;http://logger.info&quot;&amp;gt;logger.info&amp;lt;/a&amp;gt; { &quot;some message&quot; }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;They look similar but they do have one major difference tucked away in the source that is not made obvious in the rdoc. When using the block form, the block is evaluated after the level check is made. This is an important difference.&lt;/p&gt;
&lt;p&gt;Lets have a look at some sample programs to get a feel for what I am talking about.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Benchmark.bmbm do |x|
  x.report(&quot;string form&quot;) {
    100_000.times do
      logger.debug &quot;a simple string message&quot;
    end
  }
  x.report(&quot;block form&quot;) {
    100_000.times do
      logger.debug { &quot;a simple string message&quot; }
    end
  }
end

# Rehearsal -----------------------------------------------
# string form   0.140000   0.000000   0.140000 (  0.146751)
# block form    0.330000   0.010000   0.340000 (  0.336446)
# -------------------------------------- total: 0.480000sec
#
#                   user     system      total        real
# string form   0.140000   0.000000   0.140000 (  0.144761)
# block form    0.320000   0.000000   0.320000 (  0.326912)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At first glance it looks like my point is invalid. Simple strings flat out beat the block form. But if you take a moment to think about what is actually happening then this makes sense. Ruby just needs to construct a string something that it can optimize, instead of bundling up all the necessary context data in a block.&lt;/p&gt;
&lt;p&gt;But most of the time when you are logging you need to add some data to that message.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;array = []
1.upto(10) {|i| array &amp;amp;lt;&amp;amp;lt; i}

Benchmark.bmbm do |x|
  x.report(&quot;string form&quot;) {
    100_000.times do
      logger.debug &quot;a message with #{array.inspect}&quot;
    end
  }
  x.report(&quot;block form&quot;) {
    100_000.times do
      logger.debug { &quot;a message with #{array.inspect}&quot; }
    end
  }
end

# Rehearsal -----------------------------------------------
# string form   0.910000   0.000000   0.910000 (  0.914628)
# block form    0.320000   0.000000   0.320000 (  0.322889)
# -------------------------------------- total: 1.230000sec
#
#                   user     system      total        real
# string form   0.900000   0.000000   0.900000 (  0.911639)
# block form    0.330000   0.000000   0.330000 (  0.329468)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we're just inspecting a 10 item array, but already we can see that the block version hasn't budged in terms of execution time, but the string version has crept up a little. Now lets take a look at some more extreme examples.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;array = []
1.upto(1_000) {|i| array &amp;amp;lt;&amp;amp;lt; i}

Benchmark.bmbm do |x|
  x.report(&quot;string form&quot;) {
    100_000.times do
      logger.debug &quot;a message with #{array.inspect}&quot;
    end
  }
  x.report(&quot;block form&quot;) {
    100_000.times do
      logger.debug { &quot;a message with #{array.inspect}&quot; }
    end
  }
end

# Rehearsal -----------------------------------------------
# string form  65.790000   0.260000  66.050000 ( 68.107083)
# block form    0.330000   0.000000   0.330000 (  0.338018)
# ------------------------------------- total: 66.380000sec
#
#                   user     system      total        real
# string form  65.480000   0.250000  65.730000 ( 68.099213)
# block form    0.330000   0.000000   0.330000 (  0.350882)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We're now taking over 1 minute to loop over all those debug messages. The block version is almost 150 times quicker!&lt;/p&gt;
&lt;p&gt;One more example just to drive my message home. This example is what drove me to write this post. I encountered some logging just like this in a map/reduce library. The library was attempting to log, albeit at the debug level, the entire entry data set for the map process. Even though I was running my evaluation script at the ERROR log level, it looked like the master process had locked up in a busy loop, but really the process was just trying to construct a string object that was going to be discarded in 3 lines anyways.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;array = []
1.upto(1_000_000) {|i| array &amp;amp;lt;&amp;amp;lt; i}

Benchmark.bmbm do |x|
  x.report(&quot;string form&quot;) {
    100.times do
      logger.debug &quot;a message with #{array.inspect}&quot;
    end
  }
  x.report(&quot;block form&quot;) {
    100.times do
      logger.debug { &quot;a message with #{array.inspect}&quot; }
    end
  }
end

# Rehearsal -----------------------------------------------
# string form  94.360000   1.990000  96.350000 ( 97.137403)
# block form    0.000000   0.000000   0.000000 (  0.000299)
# ------------------------------------- total: 96.350000sec
#
#                   user     system      total        real
# string form  94.370000   2.080000  96.450000 ( 97.750037)
# block form    0.000000   0.000000   0.000000 (  0.000245)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I got impatient waiting for 100_000 iterations of this benchmark and dropped it to just 100.&lt;/p&gt;
&lt;p&gt;So what's the moral of the story. You need to be aware of what you are logging. Keep in mind the amount of effort that is being spent in order to construct that lovely log message. I'll leave you with another sample program that hopefully showcases some other common logging tasks.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;array = []
1.upto(10) {|i| array &amp;amp;lt;&amp;amp;lt; i}

attributes = {
  :id =&amp;gt; 1,
  :title =&amp;gt; &quot;Super Simple Ruby Performance Tip&quot;,
  :published_at =&amp;gt; Date.today,
  :tags =&amp;gt; [&quot;ruby&quot;, &quot;performance&quot;, &quot;tips&quot;],
  :categories =&amp;gt; [&quot;Ruby&quot;]
}

Benchmark.bmbm do |x|
  x.report(&quot;string form (array.first)&quot;) {
    100_000.times do
      logger.debug &quot;a message with #{array.first}&quot;
    end
  }
  x.report(&quot;string form (array.inspect)&quot;) {
    100_000.times do
      logger.debug &quot;a message with #{array.inspect}&quot;
    end
  }
  x.report(&quot;string form (attributes.inspect)&quot;) {
    100_000.times do
      logger.debug &quot;a message with #{attributes.inspect}&quot;
    end
  }
  x.report(&quot;block form (array.first)&quot;) {
    100_000.times do
      logger.debug { &quot;a message with #{array.first}&quot; }
    end
  }
  x.report(&quot;block form (array.inspect)&quot;) {
    100_000.times do
      logger.debug { &quot;a message with #{array.inspect}&quot; }
    end
  }
  x.report(&quot;block form (attributes.inspect)&quot;) {
    100_000.times do
      logger.debug { &quot;a message with #{attributes.inspect}&quot; }
    end
  }
end

# Rehearsal --------------------------------------------------------------------
# string form (array.first)          0.230000   0.000000   0.230000 (  0.239445)
# string form (array.inspect)        0.900000   0.010000   0.910000 (  0.918498)
# string form (attributes.inspect)   2.050000   0.000000   2.050000 (  2.056928)
# block form (array.first)           0.320000   0.010000   0.330000 (  0.330422)
# block form (array.inspect)         0.350000   0.000000   0.350000 (  0.347880)
# block form (attributes.inspect)    0.320000   0.000000   0.320000 (  0.326636)
# ----------------------------------------------------------- total: 4.190000sec
#
#                                        user     system      total        real
# string form (array.first)          0.240000   0.000000   0.240000 (  0.237537)
# string form (array.inspect)        0.900000   0.010000   0.910000 (  0.907226)
# string form (attributes.inspect)   2.040000   0.000000   2.040000 (  2.063976)
# block form (array.first)           0.320000   0.000000   0.320000 (  0.332216)
# block form (array.inspect)         0.330000   0.010000   0.340000 (  0.330169)
# block form (attributes.inspect)    0.330000   0.000000   0.330000 (  0.328436)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://gist.github.com/voidlock/145400&quot;&gt;Full Program&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">A New Home</title>
    <id>http://typicalnoise.com/post/a-new-home</id>
    <updated>2015-03-05T09:56:00.517000Z</updated>
    <published>2008-05-07T03:33:00Z</published>
    <link href="http://typicalnoise.com/post/a-new-home" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <content type="html">&lt;p&gt;A long time ago, Dan and I decided we should split off and do our own personal blogs separately from &lt;a href=&quot;http://twologic.com/&quot;&gt;twologic&lt;/a&gt;. We decided that twologic would simply aggregate data from both our personal blogs.&lt;/p&gt;
&lt;p&gt;So here is my very own place. So as you can see, I’ve already brought my prior articles over to their new home and you can expect a few more articles out of me in the near future. I have been silent for far too long.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Now on Google Code</title>
    <id>http://typicalnoise.com/post/now-on-google-code</id>
    <updated>2015-03-05T09:56:00.873000Z</updated>
    <published>2007-08-19T03:31:00Z</published>
    <link href="http://typicalnoise.com/post/now-on-google-code" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;I have become increasingly busy (a.k.a. lazy), and no longer wish to maintain a darcs repository or setup some sort of issue tracking. So I have left that up to google. The project is now hosted over at &lt;a href=&quot;http://code.google.com/p/inheritance/&quot;&gt;http://code.google.com/p/inheritance/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Over the next few days I will be updating the project page hosted here and moving more things over to google code. As of right now, the entire source tree is in revision control over there along with the latest 2.3 version download (contains the new Singleton stuff).&lt;/p&gt;
&lt;p&gt;Feel free to start leaving tickets.&lt;/p&gt;
&lt;p&gt;UPDATE: I got a little ahead of myself here. I accidently let some experimental code into the 2.3 release. If you have already downloaded the 2.3 release please upgrade to version 2.4.&lt;/p&gt;
&lt;p&gt;For the curious, version 2.3 contained two versions of the new &lt;code&gt;singleton&lt;/code&gt; method. In version 2.4 I moved what was labeled &lt;code&gt;singleton2&lt;/code&gt; into the &lt;code&gt;singleton&lt;/code&gt; method and removed all references to &lt;code&gt;singleton2&lt;/code&gt;.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Support for Singletons Added</title>
    <id>http://typicalnoise.com/post/support-for-singletons-added</id>
    <updated>2015-03-05T09:56:03.367000Z</updated>
    <published>2007-08-12T23:00:00Z</published>
    <link href="http://typicalnoise.com/post/support-for-singletons-added" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;I recently received an emailed from Nicholas Barthelemy of &lt;a href=&quot;http://www.nbarthelemy.com&quot;&gt;http://www.nbarthelemy.com&lt;/a&gt; regarding a little method he had written for creating Singletons with my inheritance library. Using Singletons in Javascript is something I do quite frequently, but I have always thought about them in the traditional Javascript sense (more on this later). I'd like to thank Nicholas for sending his email and for sparking my interest in adding support for the more classical style of Singleton.&lt;/p&gt;
&lt;p&gt;Now without further ado, for your coding pleasure...I introduce Class.singleton!&lt;/p&gt;
&lt;p&gt;But first a little background...&lt;/p&gt;
&lt;p&gt;In its most basic form, a singleton in Javascript can be written quite simply using basic object notation.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var Singleton = {
  property: 'value',
  someMethod: function() {
  },
  otherMethod: function() {
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can however get a little fancier and include some private data with your Singleton by taking advantage of closures.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var FancySingleton = (function() {

  // private variables and functions
  var secret = 'top secret';

  function decodeSecrets() {
    // ...
  }

  // return my public methods
  return {
    decrypt: function(code) {
      // public functions can access private
      // data and functions
      return decodeSecrets(code);
    }
  };
})();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All this is great and you've probably seen this style of Javascript in many many locations. However, if you come from a classical inheritance background you may have noticed that this style of code more resembles a namespace, or a Ruby module, or just simply as a Class with a pile of static methods and properties. In fact, this style of Javascript can be used and is used to namespace code in many libraries current available.&lt;/p&gt;
&lt;p&gt;In a classical pattern sense, a Singleton is a class that has at least one static method you can use to obtain the only instance of that class (See: Singleton Pattern). None of the examples previously shown have this. Class.singleton brings this classical approach back to Javascript.&lt;/p&gt;
&lt;p&gt;In its most basic form &lt;code&gt;Class.singleton&lt;/code&gt; can be used just like &lt;code&gt;Class.extend&lt;/code&gt; (&lt;code&gt;Class.create&lt;/code&gt; for those Prototype-ists).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// define your App's singleton
var Application = Class.singleton({
  initialize: function() {
    // initializer function, called only once
    this.member = 'an instance member';
  },
  doSomething: function() {
    // ...
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far, aside from using a different method, this looks nothing different from &lt;code&gt;Class.extend&lt;/code&gt;. However, there are actually quite a few differences. If you tried to access any of the public methods you defined an error will be thrown by the Javascript engine.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// will not work, JS throws error
Application.doSomething();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you were to inspect the Application object you might be a little worried since none of the methods you defined are actually attached to the Application object. In fact, it will contain only a single method &lt;code&gt;getInstance&lt;/code&gt;. Just like you'd expect in the classical pattern, that &lt;code&gt;getInstance&lt;/code&gt; function is used to obtain the only instance of Application class.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// get the instance
var app = Application.getInstance();

// will work now
app.doSomething();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I use a lazy loading technique to create the singleton instance the first time &lt;code&gt;getInstance&lt;/code&gt; is called. This is when the initialize function that you defined will be called.&lt;/p&gt;
&lt;p&gt;So what happens when you want to create a Singleton that inherits behavior from a base Singleton, or any Class for that matter. Well, that's just as simple as you would think. Again the parameter format matches &lt;code&gt;Class.extend&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// We need a better Application, that builds upon
// our existing Applications behaviours
var BetterApplication = Class.singleton(Application, {
  initialize: function() {
    // remember, I am called just once

    // call my parent constructor
    this.parent();

    // initialize more members
    this.newMember = 'yet another member';
  },

  // add more methods
  doMoreThings: function() {
    // ...
  }
});

var better = BetterApplication.getInstance();
app.doSomething();
app.doMoreThings();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above code will create a &lt;code&gt;BetterApplication&lt;/code&gt; singleton object that inherits functionality from &lt;code&gt;Application&lt;/code&gt;.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Long awaited project page arrives</title>
    <id>http://typicalnoise.com/post/long-awaited-project-page-arrives</id>
    <updated>2015-03-05T09:56:06.277000Z</updated>
    <published>2007-08-03T22:54:00Z</published>
    <link href="http://typicalnoise.com/post/long-awaited-project-page-arrives" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;Well, I finally got rid of my laziness. Well, at least for most of the weekend. The lame Inheritance.js project page has finally been updated. There is now some real content there, not just some lame page saying there is &quot;more to come in just a little while&quot;. Head on over to pick up the javascript file and see the latest explanation of what Inheritance.js can do for you.&lt;/p&gt;
&lt;p&gt;What''s in store for the future? Well, I''ve decided that I want to devote a portion of my free time, no matter how little there is, to working on open source software. I feel that I have a lot more I could contribute to the community of developers out there. I have my eyes on a few specific projects that I would like to get involved with, but we shall see if that works out. In terms of what the future holds for Inheritance.js, well I plan to get some sort of issue tracking system up in place. I don''t expect there to be many issues, but inevitably there will be. An issue tracking system would also be a great place for people to post suggestions for improvements and other ideas regarding the enhancement of this library. So stay tuned over the next little while for another update in that regard.&lt;/p&gt;
&lt;p&gt;As a side note, I have submitted Inheritance.js as one of Prototype''s &quot;best built-with-Prototype third-party libraries&quot;. With any luck, hopefully you''ll see Inheritance.js on the official Prototype list when it comes out.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Prototype Patch Re-submitted</title>
    <id>http://typicalnoise.com/post/prototype-patch-re-submitted</id>
    <updated>2015-03-05T09:56:06.644000Z</updated>
    <published>2007-07-28T22:50:00Z</published>
    <link href="http://typicalnoise.com/post/prototype-patch-re-submitted" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;Well I finally got off my high horse and made some time to build out a collection of unit tests for my inheritance library. I took the latest code along will all the newly written unit tests and bundled them into a nice patch for prototype. I re-attached them to my original patch so hopefully it will be included in a future version.&lt;/p&gt;
&lt;p&gt;Now that I have your attention, I thought I'd spend a bit of time to discuss some code I discovered while building out this latest set of unit tests. While looking through the scriptaculous unit testing suite I found a neat little entry at the bottom of unittest.js. I'm not sure when it was added, so if this is really old news I apologize for being behind the times.&lt;/p&gt;
&lt;p&gt;At the bottom of unittest.js there is an experimental BDD implementation in the works. This is neat, I've seen BDD (Behavior Driven Development) frameworks in Java as well as Ruby and now there's an implementation for JavaScript.&lt;/p&gt;
&lt;p&gt;So what does all this mean? Well, it means you can write your unit tests like a product specification. Using an example from RSpec, we can write the following test suite that reads like a specification:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var stack;

Test.context(&quot;An empty stack&quot;, {

  setup: function() {
    stack = new Stack();
  },

  &quot;should be empty&quot;: function() {
    assertReturnsTrue('empty', stack)
  },

  &quot;should no longer be empty after 'push'&quot;: function(){
    stack.push(&quot;anything&quot;);
    assertReturnsFalse('empty', stack)
  },

  &quot;should complain when sent 'peek'&quot;: function(){
    assertRaise('StackUnderflowError',
      function(){stack.peek()});
  },

  &quot;should complain when sent 'pop'&quot;: function(){
    assertRaise('StackUnderflowError',
      function(){stack.pop()});
  }

});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, in true BDD fashion, we should actually write our Stack implementation. Our test suite not only acts like the specification but allows us to programatically ensure that the Stack implementation we do end up writing meets that specification as well.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Updated OO Library</title>
    <id>http://typicalnoise.com/post/updated-oo-library</id>
    <updated>2015-03-05T09:56:07.029000Z</updated>
    <published>2007-07-28T02:19:00Z</published>
    <link href="http://typicalnoise.com/post/updated-oo-library" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;It has been a while since I last posted and I just wanted to make a quick announcement. Version 2.2 of my Ruby style OO library is now ready for public consumption. It has been sitting around in my darks repository for a good little while now. This new version is functionally identical to the version I last blogged about. The only change I have made is a slight alteration based on some feedback I received from Justin Palmer of EncyteMedia.&lt;/p&gt;
&lt;p&gt;In this new version I renamed &lt;code&gt;Class.create&lt;/code&gt; to &lt;code&gt;Class.extend&lt;/code&gt;, but before you go off on a frantic search and replace. Don't worry, because even though the Class.create method is now deprecated, it won’t disappear for a little while.&lt;/p&gt;
&lt;p&gt;So what prompted me to make this change?&lt;/p&gt;
&lt;p&gt;Well, Justin pointed a subtle difference between my syntax and the syntax used by Dean Edward's Base.js library.&lt;/p&gt;
&lt;p&gt;From Dean Edward's library:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var Square = Shape.extend({ ...
as apposed to my library.

var Square = Class.create(Shape, { ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In Justin's opinion the syntax of the first version is much more concise than the syntax found in my version. I concur, however in order to achieve that kind of syntax Shape has to have the method extend injected into it's definition by the OO library. This breaks one of the additional set of rules I had defined for my own library. In an effort to make the syntax of my own library a bit more concise I moved the core functionality into Class.extend as seen here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var Square = Class.extend(Shape, { ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It's still not nearly as concise, but I feel it is a good compromise. At least the verb &lt;code&gt;extend&lt;/code&gt; makes more sense than &lt;code&gt;create&lt;/code&gt; in this particular use.&lt;/p&gt;
&lt;p&gt;One finally word of warning for those intending to mix my library with Prototype. Even though &lt;code&gt;Class.extend&lt;/code&gt; is now the preferred method for creating and extending your own Classes, you are still required to include my library after Prototype in your own work.&lt;/p&gt;
&lt;p&gt;Once again head on over to the &lt;a href=&quot;https://github.com/voidlock/inheritance&quot;&gt;project page&lt;/a&gt; to grab the javascript file.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Javascript OO Ruby Style</title>
    <id>http://typicalnoise.com/post/javascript-oo-ruby-style</id>
    <updated>2015-03-05T09:56:07.541000Z</updated>
    <published>2007-06-14T05:20:00Z</published>
    <link href="http://typicalnoise.com/post/javascript-oo-ruby-style" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;This is a follow up post regarding the OO inheritance javascript library I blogged about earlier. I planned on submitting my original work as a patch to Prototype. Before submitting my patch at the rails development site I checked out the competition. I found a couple OO implementations already in contention for the next major version of Prototype. For the curious, both of them are mentioned on Sam Stephenson's &lt;a href=&quot;http://sam.&amp;lt;a%20href=&amp;quot;http://conio.net/&amp;quot;&amp;gt;conio.net/&amp;lt;/a&amp;gt;&quot;&gt;weblog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I spent some time looking over both solutions. Each one tried and did a very good job of implementing OO features, but they both had parts I didn't like. One author thought it would be neat to add support for private methods. This is neat, but I don't think javascript really needs this. People have been writing javascript for years without it and every attempt I've seen to add it to the language has seemed kind of hackish, well at least to me. You'll find my biggest beef with both libraries when you inspect an instance of one of your classes. You'll find a couple added methods and properties that the library injects so that it can do it's job. In fact even my previous OO library was guilty of this, something that bugged me to no end.&lt;/p&gt;
&lt;p&gt;So I sat down one evening and rewrote the core of my own library to meet all my demands and expectations. I am proud to say that the new library is much smaller, sleeker and generally just feels better than the first. I also added some neat new features along the way.&lt;/p&gt;
&lt;p&gt;Visit the project page for details on how to get the library.&lt;/p&gt;
&lt;p&gt;Just like Dean Edwards, I want an OO library that solves a number of problems.&lt;br /&gt;
For convenience, here is Dean's list.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dean.edwards.name/weblog/2006/03/&quot;&gt;http://dean.edwards.name/weblog/2006/03/&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I want to easily create classes without theMyClass.prototype cruft&lt;/li&gt;
&lt;li&gt;I want method overriding with intuitive access to the overridden method (like Java’s super)&lt;/li&gt;
&lt;li&gt;I want to avoid calling a class’ constructor function during the prototyping phase&lt;/li&gt;
&lt;li&gt;I want to easily add static (class) properties and methods&lt;/li&gt;
&lt;li&gt;I want to achieve the above without resorting to global functions to build prototype chains&lt;/li&gt;
&lt;li&gt;I want to achieve the above without affectingObject.prototype&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, I have a few additions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I want a more Ruby like feel to creating and working with Objects.&lt;/li&gt;
&lt;li&gt;I want to achieve all of the above without adding additional baggage to final object.&lt;/li&gt;
&lt;li&gt;I want to achieve all of the above while maintaining backward compatibility with Prototype.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So what's so new and great with my OO library? Well, since creating the first version I've learned a few neat tricks to help achieve my goals. First lets talk about mixins. Previously you had to define your mixins on a separate line&lt;br /&gt;
after your class definition.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Debug = {
  log: function(msg) {
    alert(msg);
  }
};

Employee = Class.create({
  initialize: function() {
    this.log(&quot;In the Employee constructor!&quot;);
  }
});
Class.mixin(Employee.prototype, Debug);

Client = Class.create({
  initialize: function() {
    this.log(&quot;In the Client constructor!&quot;);
  }
});
Class.mixin(Client.prototype, Debug);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Well I've added a bit of syntax sugar that in turn adds more Ruby flavor. It’s now possible to statically define an objects mixins within the class definition.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Comparable = {
  // define methods...
};
Debug = {
  // define methods...
};
Employee = Class.create({
  // define a single mixin
  include: Debug,
  initialize: function() {
    // ...
  }
});
Client = Class.create({
  // define an array of mixins
  include: [Debug, Comparable],
  initialize: function() {
    // ...
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each element given to the include property will have all of it's methods mixed into the objects' s definition. All standard rules for Ruby mixins are followed and apply when added this way. Also, it's worth noting that the &lt;code&gt;include&lt;/code&gt; property will be removed from the object's definition. This way you won't see it when you inspect instances of your class.&lt;/p&gt;
&lt;p&gt;The second improvement is in the &lt;code&gt;this.parent()&lt;/code&gt; method. It's now smart enough to recognize what method it is being used inside of, so you no longer have to explicitly tell it what method to call.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager = Class.create(Employee, {
  initialize: function(name, dept, title) {
    this.parent(name, dept);
    this.title = title;
  },
  doWork: function() {
    this.parent();
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you have defined a property or method using the same name, it will overwritten. It's also important to note that the 'this.parent()' method is only available inside a method definition. Doing something like the following will result in a javascript error.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var joe = new Manager();
joe.parent();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last visible difference between this version and my previous is that I no longer force properties into the generated objects. This is best demonstrated with an example.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Debug = {
  log: function(msg) {
    document.writeln(msg);
  }
}

Employee = Class.create({
  initialize: function(name, dept) {
    &amp;lt;a href=&quot;http://this.name&quot;&amp;gt;this.name&amp;lt;/a&amp;gt; = name;
    this.dept = dept;
  },
  doWork: function() {
    return &amp;lt;a href=&quot;http://this.name&quot;&amp;gt;this.name&amp;lt;/a&amp;gt; + &quot; is now working...&quot;;
  }
});

Manager = Class.create(Employee, {
  include: Debug,
  initialize: function(name, dept, title) {
    this.parent(name, dept);
    this.title = title;
  },
  doWork: function() {
    this.log(this.parent() + &quot;at managing the employees.&quot;);
  }
});

var joe = new Manager(&quot;Joe&quot;, &quot;Sales&quot;, &quot;Sales Manager&quot;);
joe.doWork()

var out = &quot;&quot;;
for (var p in joe) {
  out += p + &quot;: &quot; + joe[p] + &quot;,\\n&quot;
}
out = out.substring(0, out.length - 2);
Debug.log(&quot;Manager {\\n&quot; + out + &quot;\\n}&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Outputs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Joe is now working...at managing the employees.
Manager {
  name: Joe,
  dept: Sales,
  title: Sales Manager,
  initialize: function (name, dept, title) {
    this.parent(name, dept);
    this.title = title;
  },
  doWork: function () {
    this.log(this.parent() + &quot;at managing the employees.&quot;);
  },
  log: function (msg) {
    document.writeln(msg);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see the &lt;code&gt;for (var p in joe)&lt;/code&gt; construct returns exactly what you defined. There are no extra methods or properties visibly added to you object to make any of this work. You can also see that the log method was mixed into the class definition and the include property no longer exists.&lt;/p&gt;
&lt;p&gt;Visit the &lt;a href=&quot;https://github.com/voidlock/inheritance&quot;&gt;project page&lt;/a&gt; for details on how to get the library.&lt;/p&gt;</content>
  </entry>
  <entry xml:base="http://typicalnoise.com/feed.xml">
    <title type="text">Object Inheritance with Javascript</title>
    <id>http://typicalnoise.com/post/object-inheritance-with-javascript</id>
    <updated>2015-03-05T09:56:07.759000Z</updated>
    <published>2007-05-19T05:11:00Z</published>
    <link href="http://typicalnoise.com/post/object-inheritance-with-javascript" />
    <author>
      <name>Alex Arnell</name>
    </author>
    <category term="javascript" />
    <content type="html">&lt;p&gt;Recently I've been spending a lot of my time experimenting with and writing web-applications powered by a fair bit of Javascript. I've toyed with a couple of the new big hitters in the world of Javascript; namely Prototype and MochiKit. If you haven't heard of either library, I encourage you to take a peak and explore them both. They provide a large set of useful functions and features that will help to save you time when writing your own Javascript. I'm not about to discuss which one is better than the other, nor am I going to do a feature comparison between both libraries. There are plenty of articles and blog posts that already do just that. Instead I am going to focus on something else; something that neither of those two libraries really help with. I am going to focus on writing Object-Oriented Javascript.&lt;/p&gt;
&lt;p&gt;There are a lot of pitfalls and not so attractive code that is needed in order to accomplish certain OO tasks in Javascript. I've written a little library that I think helps to simplify all this. However, before I get into the details of my own work, I think a little background is in order. Of course, you could skip right down to it if you are already familiar with the pitfalls of writing OO in Javascript.&lt;/p&gt;
&lt;h3&gt;A little background&lt;/h3&gt;
&lt;p&gt;As many readers may already know Javascript is a prototype-based language3. It is possible to define your own objects, however the syntax for doing so is somewhat clumsy. I won't go into all the details on how to create objects since you can read them for yourself in the Core Javascript Guide, but here's a brief rundown.&lt;/p&gt;
&lt;p&gt;Traditionally the following code would define a constructor function for our Employee object.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Employee = function() {
  &amp;lt;a href=&quot;http://this.name&quot;&amp;gt;this.name&amp;lt;/a&amp;gt; = '';
  this.dept = &quot;general&quot;;

};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Methods can be added to our Employee object with the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Employee.prototype.doWork = function() {
  return &quot;Employee is working...&quot;;
};

Employee.prototype.takeBreak = function() {
  return &quot;Employee is slacking off...&quot;;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above code is quite verbose and cumbersome. Alternatively, the following syntax will achieve the same effect.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Employee.prototype = {
  doWork: function() {
    return &quot;Employee is working...&quot;;
  },
  takeBreak: function() {
    return &quot;Employee is slacking off...&quot;;
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a bit cleaner, however defining your object still requires two independent chunks of code. Also, the situation just gets even worse when you try and create a hierarchy of objects.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager = function() {
  this.reports = [];
};
Manager.prototype = new Employee();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have defined Manager to be a subclass of Employee. However, now your only option to add methods to our Manager object is to use the traditional way.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager.prototype.manage = function() {
  return &quot;Manager is now micro-managing...&quot;;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following will not work because we would loose our object hierarchy.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager.prototype = {
  manage: function() {
    return &quot;Manager is now micro-managing...&quot;;
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are using either of the Prototype or MochiKit libraries you can however cheat a little here and use a handy feature that is present in both libraries.&lt;/p&gt;
&lt;p&gt;Using Prototype:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager.prototype = Object.extend(new Employee(), {
  manage: function() {
    return &quot;Manager is now micro-managing...&quot;;
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using MochiKit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager.prototype = MochiKit.Base.update(new Employee(), {
  manage: function() {
    return &quot;Manager is now micro-managing...&quot;;
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Object.extend(..)&lt;/code&gt; and &lt;code&gt;MochiKit.Base.update(..)&lt;/code&gt; both perform the same task of mutating and returning the first parameter replacing all of it's key:value pairs with those from the second parameter. This allows you to create an object hierarchy and keep using the cleaner syntax for defining your Objects methods.&lt;/p&gt;
&lt;p&gt;All of this works great until you want to call a method on a parent class. There is no nice way of doing this natively in Javascript. Instead, you have use some rather explicit and gross looking code the uses either Function.apply or Function.call.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager.prototype.doWork = function() {
  return Employee.prototype.doWork.call(this) +
    &quot;managing the rest of the employees.&quot;;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This bit of code isn't very nice for a number of reasons. The one reason I dislike the most about this bit of code is that it doesn't make life easy if you ever come back and alter your work. Lets say your hierarchy changes and Managers are no longer Employees, instead they are Owners. Now you have to go searching through all your code looking for all the cases where you &lt;code&gt;calledEmployee.prototype.someFunc.call(..)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There isn't really a nice way around this without adding some additional features to the language. I spent some time the other evening trying to piece together a nice extension that will make the syntax for writing Objects cleaner and simpler, while still playing nicely with those big hitting libraries. The complete JS is available for download at the bottom of this post. The next few examples will demonstrate how to use my little extension.&lt;/p&gt;
&lt;h3&gt;The Good Stuff&lt;/h3&gt;
&lt;p&gt;I've created a Class object that mimics the Class object found in the Prototype library. If you already use Prototype, your old code should continue to work without any side effects. At the core of my extension is the &lt;code&gt;Class.create()&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;In order to create a new Object you can use the following syntax (if you use the Prototype library already, then this will be familiar).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Employee = Class.create();
Employee.prototype = {
  initialize: function() {
    &amp;lt;a href=&quot;http://this.name&quot;&amp;gt;this.name&amp;lt;/a&amp;gt; = &quot;&quot;;
    this.dept = &quot;general&quot;;
  },
  doWork: function() {
    return &quot;Employee is working...&quot;;
  },
  takeBreak: function() {
    return &quot;Employee is slacking off...&quot;;
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;p&gt;So what is this doing? In this case &lt;code&gt;Class.create()&lt;/code&gt; creates a constructor function for us. The created constructor will call the initialize method on Object creation. So in essence we can treat initialize as our constructor. So far this functionally the same as the &lt;code&gt;Class.create()&lt;/code&gt; method found in the Prototype Library, however thats not all I have done. I took this idea one step further and combined both the constructor creation and the prototype definition in one convenient call.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Employee = Class.create({
  initialize: function() {
    &amp;lt;a href=&quot;http://this.name&quot;&amp;gt;this.name&amp;lt;/a&amp;gt; = &quot;&quot;;
    this.dept = &quot;general&quot;;
  },
  doWork: function() {
    return &quot;Employee is working...&quot;;
  },
  takeBreak: function() {
    return &quot;Employee is slacking off...&quot;;
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above code will create the Employee object we created earlier. You no longer have to separate your Object definition into two pieces. Its all done at the same time.&lt;/p&gt;
&lt;p&gt;But wait, there's more! I took it another step further. What happens when you want to create an object hierarchy?Class.create() can do that too!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager = Class.create(Employee, {
  manage: function() {
    return &quot;Manager is now micro-managing...&quot;;
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now using a very simple syntax we've created our Manager Object, that inherits functionality from Employee and we've defined the manage method that only Managers have.&lt;/p&gt;
&lt;p&gt;Well what about that problem of calling methods defined in the parent class? Well if you create your Objects using the above Class.create() syntax, then you will find a special helper method already defined in each of your Objects.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Manager = Class.create(Employee, {
  //...
  doWork: function() {
    this.parent('doWork');
  }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The parent method is defined internally when you create an Object using Class.create(). The parent method takes two parameters, the first is the method to call and the second optional parameter is an array of arguments to pass to that method.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  this.parent('doWork');
  this.parent('doWork', [param1, param2, ...]);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The parent method is inspired from the way messaging works in Objective-C and borrows some naming conventions from Ruby. It will look in the parent class for the given method. If it cannot find it there it will continue the search upwards in every parent class until it reaches the top of the chain. If at this point it still cannot find an implementation of that method it calls a specialmethod_missing method, which you can override to do something special if you so wish. The defaultmethod_missing implementation just throws an error.&lt;/p&gt;
&lt;h3&gt;Mixins&lt;/h3&gt;
&lt;p&gt;The last thing worth mentioning is the &lt;code&gt;Class.mixin()&lt;/code&gt; method, which is identical to Prototype's &lt;code&gt;Object.extend()&lt;/code&gt; method or the &lt;code&gt;MochiKit.Base.update()&lt;/code&gt; function. I believe mixin is a better name since, you are essentially mixing in the key:value pairs from another object. You can use this method to mixin common functionality. This works very similarly to mixin support you find in other languages such as Ruby.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Debug = {
  log: function(msg) {
    alert(msg);
  }
};

Employee = Class.create({
  initialize: function() {
    this.log(&quot;In the Employee constructor!&quot;);
  }
});
Class.mixin(Employee.prototype, Debug);

Client = Class.create({
  initialize: function() {
    this.log(&quot;In the Client constructor!&quot;);
  }
});
Class.mixin(Client.prototype, Debug);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now both Employee and Client objects have an identical log method.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var e = new Employee();
// alert with message &quot;In the Employee constructor!&quot; will be seen

var c = new Client();
// another alert with message &quot;In the Client constructor!&quot; will be seen
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have included class.js into a project I have on the go write now, and I plan on incorporating class.js into several other projects that have been put on the back-burner but should come back to life soon. The source is available via darcs, and more documentation will start appearing soon as well.&lt;/p&gt;
&lt;p&gt;I have a few additional ideas for improving upon this extension, and there is still one final gotcha that needs to be overcome. I will leave that for another post however, since this one is already long enough.&lt;/p&gt;
&lt;h3&gt;And Finally, The Goods&lt;/h3&gt;
&lt;p&gt;Project page and just the inheritance.js file.&lt;/p&gt;
&lt;p&gt;code repository: &lt;a href=&quot;https://github.com/voidlock/inheritance&quot;&gt;https://github.com/voidlock/inheritance&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
</feed>
