<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:at="http://www.sixapart.com/ns/at"
    xmlns:icbm="http://postneo.com/icbm"
    xmlns:rvw="http://purl.org/NET/RVW/0.2/"
    xmlns:media="http://search.yahoo.com/mrss">
    <channel>
        <title>ydnar</title>
        <link>http://ydnar.vox.com/library/posts/tags/code/page/1/</link>
        <description>is living in your future</description>
        <language>en</language>
        <generator>Vox</generator>
        <lastBuildDate>Fri, 09 Feb 2007 21:57:07 -0800</lastBuildDate>
        <copyright>Copyright 2007</copyright>
        <docs>http://blogs.law.harvard.edu/tech/rss</docs> 
        <category domain="http://ydnar.vox.com/tags/">code</category>  
 
        <item>
            <title>Refining Superclass Method Calls in JavaScript</title>
            <link>http://ydnar.vox.com/library/post/refining-superclass-method-calls-in-javascript.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(ydnar)</author>
            <comments>http://ydnar.vox.com/library/post/refining-superclass-method-calls-in-javascript.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://ydnar.vox.com/library/post/refining-superclass-method-calls-in-javascript.html?_c=feed-rss-full</guid> 
            <pubDate>Fri, 09 Feb 2007 21:57:07 -0800</pubDate>         
            
            <description>    
        &lt;p&gt;Last week I was revisiting the always fun problem of
implementing “classical” inheritance in JavaScript. I’d taken a few
stabs at it, and had gotten it to a reasonably good state that borrowed
some good ideas from &lt;a href=&quot;http://www.crockford.com/&quot;&gt;Doug Crockford&lt;/a&gt;, &lt;a href=&quot;http://www.prototypejs.org/&quot;&gt;Sam Stephenson&lt;/a&gt;, and &lt;a href=&quot;http://www.dean.edwards.name/&quot;&gt;Dean Edwards&lt;/a&gt;. Joshua Gertzen wrote a good post about various methods on &lt;a href=&quot;http://truecode.blogspot.com/2006/08/object-oriented-super-class-method.html&quot;&gt;his blog&lt;/a&gt;.&lt;/p&gt;
        
        &lt;p&gt;I’ve never been terribly thrilled with the form &lt;code&gt;Class.superClass.method.apply( this, arguments )&lt;/code&gt;.
It was redundant: replicating both the class and method names. Copy
&amp;amp; paste of code could lead to subtle errors, and it’s annoying to
type that much. But the alternatives were worse: Recompiling the
function to generate a “magic” lexical for the superclass or wrapper
methods. So the &lt;code&gt;Class&lt;/code&gt; object basically sat untouched for a year and a half.&lt;/p&gt;
        
        &lt;p&gt;Back to last week…It occurred to me that in all the JavaScript we’d built for &lt;a&gt;Vox&lt;/a&gt;,
we almost never shared a method between two objects, except via
inheritance. There were a couple exceptions, but they could be
rewritten (it turned out to be a good idea anyway). Second, functions
are objects like everything else, and can have arbitrary properties.
Third, &lt;code&gt;arguments.callee&lt;/code&gt; is available in every function
call in JavaScript. I realized then that storing the superclass was not
as useful as just storing the super&lt;em&gt;method&lt;/em&gt;.&lt;/p&gt;
        
        &lt;p&gt;For any given method in a class, store its supermethod as a property of the method: &lt;code&gt;method.__super&lt;/code&gt;. Instead of the unwieldy construct above, any method could simply use &lt;code&gt;arguments.callee.__super.apply( this, arguments )&lt;/code&gt;.&lt;/p&gt;
        
        &lt;p&gt;The &lt;code&gt;Class&lt;/code&gt; constructor from &lt;a href=&quot;http://code.sixapart.com/svn/js/trunk/common/Core.js&quot;&gt;Core.js&lt;/a&gt;:&lt;/p&gt;
        
        &lt;blockquote&gt;
&lt;pre&gt;Class = function( sc ) {&lt;br /&gt;    var c = function( s ) {&lt;br /&gt;        this.constructor = arguments.callee;&lt;br /&gt;        if( s === __SUBCLASS__ )&lt;br /&gt;            return;&lt;br /&gt;        this.init.apply( this, arguments );&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    c.override( Class );&lt;br /&gt;    sc = sc || Object;&lt;br /&gt;    c.override( sc );&lt;br /&gt;    c.__super = sc;&lt;br /&gt;    c.superClass = sc.prototype;&lt;br /&gt;&lt;br /&gt;    c.prototype = sc === Object ? new sc() : new sc( __SUBCLASS__ );&lt;br /&gt;    c.prototype.extend( Class.prototype );&lt;br /&gt;    var a = arguments;&lt;br /&gt;    for( var i = 1; i &amp;lt; a.length; i++ )&lt;br /&gt;        c.prototype.override( a[ i ] );&lt;br /&gt;&lt;br /&gt;    for( var p in c.prototype ) {&lt;br /&gt;        var m = c.prototype[ p ];&lt;br /&gt;        if( typeof m != &amp;quot;function&amp;quot; || defined( m.__super ) )&lt;br /&gt;            continue;&lt;br /&gt;        m.__super = null;&lt;br /&gt;        var pr = sc.prototype;&lt;br /&gt;        while( pr ) {&lt;br /&gt;            if( defined( pr[ p ] ) ) {&lt;br /&gt;                m.__super = pr[ p ];&lt;br /&gt;                break;&lt;br /&gt;            }&lt;br /&gt;            if( pr === pr.constructor.prototype )&lt;br /&gt;                break;&lt;br /&gt;            pr = pr.constructor.prototype;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return c;&lt;br /&gt;}&lt;/pre&gt;
        &lt;/blockquote&gt;
        
        &lt;p&gt;&lt;code&gt;arguments.callee&lt;/code&gt; was useful in the constructor too: Instead of creating a circular reference by overriding the constructor like this: &lt;code&gt;constructor.prototype.constructor = constructor&lt;/code&gt;, the constructor itself can just set it on the &lt;code&gt;this&lt;/code&gt; object when the constructor is called: &lt;code&gt;this.constructor = arguments.callee&lt;/code&gt;.&lt;/p&gt;
        
        &lt;p&gt;Calling a supermethod can be simplified further, to &lt;code&gt;arguments.callee.applySuper( this, arguments )&lt;/code&gt; via a little sugar:&lt;/p&gt;
        
        &lt;blockquote&gt;
&lt;pre&gt;Function.prototype.extend( {&lt;br /&gt;    applySuper: function( o, args ) {&lt;br /&gt;        return this.__super.apply( o, args );&lt;br /&gt;    },&lt;br /&gt;&lt;br /&gt;    callSuper: function( o ) {&lt;br /&gt;        var args = [];&lt;br /&gt;        for( var i = 1; i &amp;lt; arguments.length; i++ )&lt;br /&gt;            args.push( arguments[ i ] );&lt;br /&gt;        return this.__super.apply( o, args );&lt;br /&gt;    }&lt;br /&gt;} );&lt;/pre&gt;
        &lt;/blockquote&gt;
    
     &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://ydnar.vox.com/library/post/refining-superclass-method-calls-in-javascript.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00b8ea0674f2dece00d09e53f262be2b?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://ydnar.vox.com/tags/">javascript</category> 
            <category domain="http://ydnar.vox.com/tags/">code</category> 
            <category domain="http://ydnar.vox.com/tags/">inheritance</category> 
            <category domain="http://ydnar.vox.com/tags/">superclass</category>   
        </item> 
 
        <item>
            <title>Adobe Makes an Open Source Play</title>
            <link>http://ydnar.vox.com/library/post/adobe-makes-an-open-source-play.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(ydnar)</author>
            <comments>http://ydnar.vox.com/library/post/adobe-makes-an-open-source-play.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://ydnar.vox.com/library/post/adobe-makes-an-open-source-play.html?_c=feed-rss-full</guid> 
            <pubDate>Tue, 07 Nov 2006 07:22:59 -0800</pubDate>         
            
            <description>    &lt;p&gt;Adobe has given the Flash ActionScript (ECMAScript or JavaScript 2.0) interpreter to the Mozilla foundation as the new open source core of SpiderMonkey, the JavaScript engine for Firefox. It&amp;#39;s called &lt;a href=&quot;http://www.mozilla.org/projects/tamarin/&quot;&gt;Tamarin&lt;/a&gt;. Brilliant. &lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://ydnar.vox.com/library/post/adobe-makes-an-open-source-play.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00b8ea0674f2dece00cdf39cd267cb8f?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://ydnar.vox.com/tags/">coding</category> 
            <category domain="http://ydnar.vox.com/tags/">flash</category> 
            <category domain="http://ydnar.vox.com/tags/">javascript</category> 
            <category domain="http://ydnar.vox.com/tags/">2006</category> 
            <category domain="http://ydnar.vox.com/tags/">geek</category> 
            <category domain="http://ydnar.vox.com/tags/">adobe</category> 
            <category domain="http://ydnar.vox.com/tags/">open source</category> 
            <category domain="http://ydnar.vox.com/tags/">code</category> 
            <category domain="http://ydnar.vox.com/tags/">vm</category> 
            <category domain="http://ydnar.vox.com/tags/">compiler</category> 
            <category domain="http://ydnar.vox.com/tags/">interpreter</category> 
            <category domain="http://ydnar.vox.com/tags/">osi</category> 
            <category domain="http://ydnar.vox.com/tags/">ecmascript</category> 
            <category domain="http://ydnar.vox.com/tags/">js2</category>   
        </item> 
 
        <item>
            <title>Graphics</title>
            <link>http://ydnar.vox.com/library/post/graphics.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(ydnar)</author>
            <comments>http://ydnar.vox.com/library/post/graphics.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://ydnar.vox.com/library/post/graphics.html?_c=feed-rss-full</guid> 
            <pubDate>Wed, 23 Aug 2006 00:21:33 -0700</pubDate>         
            
            <description>    &lt;p&gt;         

    
&lt;/p&gt;
    
    
    
&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00b8ea0674f2dece00c22522d905549d&quot; at:format=&quot;medium&quot; at:align=&quot;right&quot;
    class=&quot;enclosure enclosure-right enclosure-medium photo-enclosure&quot; 
     style=&quot;text-align: center; float: right;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 0 0 20px 20px;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item photo-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d905549d.html&quot;&gt;&lt;img src=&quot;http://a5.vox.com/6a00b8ea0674f2dece00c22522d905549d-200pi&quot; alt=&quot;Basis (Sun)&quot; title=&quot;Basis (Sun)&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d905549d.html&quot; title=&quot;Basis (Sun)&quot;&gt;Basis (Sun)&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;

&lt;p&gt;         

    
&lt;/p&gt;
    
    
    
&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00b8ea0674f2dece00c22522d6d6604a&quot; at:format=&quot;medium&quot; at:align=&quot;right&quot;
    class=&quot;enclosure enclosure-right enclosure-medium photo-enclosure&quot; 
     style=&quot;text-align: center; float: right;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 0 0 20px 20px;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item photo-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d6d6604a.html&quot;&gt;&lt;img src=&quot;http://a6.vox.com/6a00b8ea0674f2dece00c22522d6d6604a-200pi&quot; alt=&quot;Negative Lights + Masking Gels&quot; title=&quot;Negative Lights + Masking Gels&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d6d6604a.html&quot; title=&quot;Negative Lights + Masking Gels&quot;&gt;Negative Lights + Masking Gels&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;

&lt;p&gt;         

    
&lt;/p&gt;
    
    
    
&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00b8ea0674f2dece00c22522d6d8604a&quot; at:format=&quot;medium&quot; at:align=&quot;right&quot;
    class=&quot;enclosure enclosure-right enclosure-medium photo-enclosure&quot; 
     style=&quot;text-align: center; float: right;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 0 0 20px 20px;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item photo-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d6d8604a.html&quot;&gt;&lt;img src=&quot;http://a0.vox.com/6a00b8ea0674f2dece00c22522d6d8604a-200pi&quot; alt=&quot;Model Cloud&quot; title=&quot;Model Cloud&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://ydnar.vox.com/library/photo/6a00b8ea0674f2dece00c22522d6d8604a.html&quot; title=&quot;Model Cloud&quot;&gt;Model Cloud&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;

&lt;p&gt;Recently dug up some old photos, er screenshots from the days when I was a graphics geek. I&amp;#39;m supposed to give a presentation about same one of these Thursdays.&lt;br /&gt;&lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://ydnar.vox.com/library/post/graphics.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00b8ea0674f2dece00c22523cd8c8e1d?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://ydnar.vox.com/tags/">graphics</category> 
            <category domain="http://ydnar.vox.com/tags/">quake</category> 
            <category domain="http://ydnar.vox.com/tags/">cg</category> 
            <category domain="http://ydnar.vox.com/tags/">2006</category> 
            <category domain="http://ydnar.vox.com/tags/">geek</category> 
            <category domain="http://ydnar.vox.com/tags/">code</category> 
            <category domain="http://ydnar.vox.com/tags/">computer graphics</category> 
            <category domain="http://ydnar.vox.com/tags/">render</category> 
            <category domain="http://ydnar.vox.com/tags/">rendering</category> 
            <category domain="http://ydnar.vox.com/tags/">q3map2</category>    
        </item> 
 
        <item>
            <title>Holy War</title>
            <link>http://ydnar.vox.com/library/post/holy-war.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(ydnar)</author>
            <comments>http://ydnar.vox.com/library/post/holy-war.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://ydnar.vox.com/library/post/holy-war.html?_c=feed-rss-full</guid> 
            <pubDate>Mon, 03 Jul 2006 14:27:34 -0700</pubDate>         
            
            <description>    &lt;p&gt;This is a &lt;a href=&quot;http://nickgravgaard.com/elastictabstops/&quot;&gt;brilliant solution to the age-old problem of tabs versus spaces&lt;/a&gt; in source code. Instead of treating tabs as indent of a fixed size, treat the source code as tabular data, where the tab character jumps to the next logical column, where the width of said column is determined by the widest point in the document.&lt;/p&gt;&lt;p&gt;(via &lt;a href=&quot;http://it.slashdot.org/article.pl?sid=06/07/03/1820235&quot;&gt;Slashdot&lt;/a&gt;)&lt;br /&gt;&lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://ydnar.vox.com/library/post/holy-war.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00b8ea0674f2dece00c2251c75d0f219?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://ydnar.vox.com/tags/">editors</category> 
            <category domain="http://ydnar.vox.com/tags/">code</category> 
            <category domain="http://ydnar.vox.com/tags/">tabs</category> 
            <category domain="http://ydnar.vox.com/tags/">slashdot</category>   
        </item> 
    </channel>
</rss>

