<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
	<channel>
		<title>McArthur GFX</title>
		<link>http://mcarthurgfx.com</link>
		<description>notes from a web developer</description>
		<pubDate>Thu, 09 Jul 2009 09:29:00 -0700</pubDate>
		<generator>http://www.blazonco.com/</generator>
		<language>en</language>
				<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/mcarthurgfx" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">mcarthurgfx</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
			<title>Requiring Login to CakePHP Admin</title>
			<link>http://mcarthurgfx.com/blog/article/requiring-login-to-cakephp-admin</link>
			<comments>http://mcarthurgfx.com/blog/article/requiring-login-to-cakephp-admin#comments</comments>
			<pubDate>Thu, 09 Jul 2009 09:29:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[PHP]]></category>
			<guid>http://mcarthurgfx.com/blog/article/requiring-login-to-cakephp-admin</guid>
			<description><![CDATA[<p>For some of my freelance clients, I have provided a home-brewed CMS, built using CakePHP, since I'd already used Cake for the rest of their web-site. I wanted to create a couple users, and an interface to be able to create pages that made up the navigation and content.</p>
<p>Building an admin area for this functionality, the first thing I did was turn on <a href="http://book.cakephp.org/view/46/Routes-Configuration#Prefix-Routing-544" target="_blank">admin routing</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>For some of my freelance clients, I have provided a home-brewed CMS, built using CakePHP, since I'd already used Cake for the rest of their web-site. I wanted to create a couple users, and an interface to be able to create pages that made up the navigation and content.</p>
<p>Building an admin area for this functionality, the first thing I did was turn on <a href="http://book.cakephp.org/view/46/Routes-Configuration#Prefix-Routing-544" target="_blank">admin routing</a>.</p>
<p>Since we're logging in Users, we build a <code>User</code> model and <code>UsersController</code>. In the User model, write whatever extra you need, but the basics is just a validation function, to match username with password when logging in.</p>
<pre><code>function validateLogin($data) {
    $user = $this-&gt;find(array(
        'username' =&gt; $data['username'],
        'password' =&gt; md5($data['password'])
        ), array('id', 'username'));
    
    return !empty($user) ? $user['User'] : false;      
}</code></pre>
<p>You can add any additional validation rules in here, and you might want to use a <a href="http://mcarthurgfx.com/blog/article/a-basic-lesson-in-password-hashing">better hashing use than simpy straight md5</a>. Anyhow, this function will be called from the <code>UsersController</code>. So let's dive into there.</p>
<h4>UsersController</h4>
<p>Throw together a simple login function. I'll let your imagination put together the view, that's just some simple html form stuff. Check for post data, validate with the above function, write the User object to the session and redirect to the admin area.</p>
<p>And conversely, logging out is simply destroying the User object from the session and redirecting out of the admin area. Simple stuff.</p>
<p>To help <em>enforce</em>logging in though, we pay attention to the filter event of controllers, and check the session first. The <a href="http://book.cakephp.org/view/60/Callbacks" target="_blank">process of a controller</a> responding to the router is <em>beforeFilter -&gt; <strong>action</strong> -&gt; beforeRender -&gt; render -&gt; afterFilter</em>. You can make sure things happen before it calls any action, by writing a beforeFilter method. You could use this method to check for things, and if it's not up to snuff, redirect to a different page. That's what we're going to do.</p>
<p>So, in the UsersController, we want to make sure that a user can't do anything pertaining to users until they login.</p>
<pre><code>function beforeFilter() {
    if($this-&gt;action != 'login' &amp;&amp; $this-&gt;action != 'logout') {
        if($this-&gt;Session-&gt;check('User') == false) {
            $this-&gt;redirect('login');
            $this-&gt;Session-&gt;setFlash('The URL you\'ve followed requires you login.');
        }
    }
}</code></pre>
<h4>Admin Requires Login</h4>
<p>The last step is ensuring that any time a user wants to access the admin part of our app, they must be a logged in user, or they the boot. This involves using the same event as above, but in the <code>AppController</code>. The <code>AppController</code> lets us write something that should happen in every controller, because by default we should be extending <code>AppController</code>.</p>
<p>However, we don't want it to <strong>always</strong>be forcing logins. Visitors who access public areas shouldn't have to login. But if they want to access the admin areas, <strong>that's</strong> when we want to force them.</p>
<p>With our admin routing turned on, any time the Router wants to invoke a method because of the <code>Routing.admin</code> configuration, it will add to the <code>params</code> of the controller <code>'admin' = 1</code>. Thus, we can easily make our filter only care if admin is set.</p>
<pre><code>class AppController extends Controller { 
    function beforeFilter() {	
        if ($this-&gt;params['admin']) {		            
            if($this-&gt;Session-&gt;check('User') == false) {	
                $this-&gt;flash('The URL you\'ve followed requires you login.','/login',2);	
            }	
            $this-&gt;layout = 'admin';	
        }	
    } 
}</code></pre>
<h4>Admin Galore</h4>
<p>Now, any page we want to setup as requiring admin access, like in my CMS, allowing admins to edit pages, we create functions prepended with value in your config for <code>Routing.admin</code>. By default, that's <code>admin</code>.</p>
<p>This simple addition now requires you be logged in (with a user made either manually by myself or using a registration form you can build into the <code>UsersController</code>) in order to see the list of pages.</p>
<pre><code>class PagesController extends AppController {
    function admin_index() {
        //setting the layout could be done in
        //the AppController beforeFilter, so all
        //admin pages use the admin layout instead.
        $this-&gt;layout = 'admin';
        
        $this-&gt;set('pages',$this-&gt;Page-&gt;getNav());	
    }   
}</code></pre>
<p>The default view for this follows the same kind of automagic rules for CakePHP: it'll be <code>app/views/pages/admin_index.ctp</code>.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=twfHk1Qf3MI:l_tstSHDiI0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=twfHk1Qf3MI:l_tstSHDiI0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=twfHk1Qf3MI:l_tstSHDiI0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=twfHk1Qf3MI:l_tstSHDiI0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=twfHk1Qf3MI:l_tstSHDiI0:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>My Syntax Highlighting</title>
			<link>http://mcarthurgfx.com/blog/article/my-syntax-highlighting</link>
			<comments>http://mcarthurgfx.com/blog/article/my-syntax-highlighting#comments</comments>
			<pubDate>Tue, 07 Jul 2009 08:00:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Tools]]></category>
			<guid>http://mcarthurgfx.com/blog/article/my-syntax-highlighting</guid>
			<description><![CDATA[<p>One of the most obvious benefits to <a href="http://www.ultraedit.com/" target="_blank">code editors</a> and <a href="http://mcarthurgfx.com/blog/article/php-designer-2008">IDEs</a> is being able to customize all the pretty colors that we must stare at for hours on end. It's our decoration. <strong>It's our wardrobe</strong>. So let me show off my own code outfitting.</p>]]></description>
			<content:encoded><![CDATA[<p>One of the most obvious benefits to <a href="http://www.ultraedit.com/" target="_blank">code editors</a> and <a href="http://mcarthurgfx.com/blog/article/php-designer-2008">IDEs</a> is being able to customize all the pretty colors that we must stare at for hours on end. It's our decoration. <strong>It's our wardrobe</strong>. So let me show off my own code outfitting.</p>
<h4>Monstar Code</h4>
<p>I've toyed around with various schemes, and have settled on my preferred colors. It might be influenced from the first time I used an editor in college (<a href="http://www.eclipse.org/" target="_blank">Eclipse</a>), but it's changed and grown some.</p>
<p>I recall some people at my former work quite liked the <a href="http://www.37signals.com/svn/posts/1773-how-to-mock-alternate-states-of-a-new-ui-template-using-helpers" target="_blank">inverted look</a>. You know, light colors on a black or dark grey background. I wanted to like it: it kinda seems cool. But ultimately it was a little too weird for me.</p>
<p>However, this is a shot of my color scheme in <a href="http://www.activestate.com/komodo/" target="_blank">Komodo</a> (I try to duplicate the scheme in any editor I use).</p>
<p><img src="http://mcarthurgfx.com/images/blog/my-syntax-highlight-scheme.jpg" alt="" /></p>
<p>I'll list the colors I use:</p>
<ul>
<li><strong>Keywords</strong> - Blue. This would things like public, function, true, false, null, if, for, return, etc.</li>
<li><strong>Variables</strong> - Light blue.</li>
<li><strong>Strings</strong> - Green.</li>
<li><strong>Operators</strong> - Black.  Arithmetic, assignment, parenthesis, the like.</li>
<li><strong>Numbers</strong> - Dark Brown.</li>
<li><strong>Comments</strong> - Grey.  I prefer comments to be more hidden unless I specifically want to read them.</li>
<li><strong>Identifiers</strong> - Black.  These are function calls, or accessing properties of objects.</li>
<li><strong>Standard Library</strong> - Red.  Methods or constants defined in the standard library, I like them to stick out so I know when I'm using native functions (ex:print_r, preg_match, etc).</li>
</ul>
<p>You'll also see that I enjoy a slightly off-white background, to cut down on the extreme photon abuse of my eyes. Just feels less... painful.</p>
<h4>Other Editors</h4>
<p>Komodo (seen above) doesn't allow me to do my last list item, coloring standard library names. I certainly wish it did, and if you know how, please do tell. However, I also use UltraEdit as it opens faster and uses less memory, and it <em>does</em>allow me to set standard functions red. I believe Eclipse allowed me to do this (it's been a while use I've used it), and my recent checking out of Aptana showed it was possible.</p>
<p>In fact, Aptana seemed to have the more power for customizing color schemes. Not only could you select colors for groups of syntax, like 'keywords', you could then drill into keywords and say specifically that for and while should be different colors.</p>
<h4>Besides Color</h4>
<p>When given the option, I also enjoy when an editor allows me to modify the fonts of specific syntax. I like making comments italic, as it just seems to help make them... sleeker, more invisible, except when I need them. I don't use it personally, but I could see benefit to maybe adding bold to identifiers, or keywords, to make sure you don't miss out on any returns, for instance.</p>
<p>Of the many differences between coders, syntax highlighting is nearly a constant. However, coloring styles differ, as certain colors might have different psychological effects on the viewer. How do <strong>you</strong>prefer to look at <strong>your</strong>code?</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=KsPuYwSgCqM:BQHNw_dGS9I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=KsPuYwSgCqM:BQHNw_dGS9I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=KsPuYwSgCqM:BQHNw_dGS9I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=KsPuYwSgCqM:BQHNw_dGS9I:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=KsPuYwSgCqM:BQHNw_dGS9I:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>A Basic Lesson in Password Hashing</title>
			<link>http://mcarthurgfx.com/blog/article/a-basic-lesson-in-password-hashing</link>
			<comments>http://mcarthurgfx.com/blog/article/a-basic-lesson-in-password-hashing#comments</comments>
			<pubDate>Wed, 01 Jul 2009 09:30:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[PHP]]></category>
			<guid>http://mcarthurgfx.com/blog/article/a-basic-lesson-in-password-hashing</guid>
			<description><![CDATA[<p>In the world of the web, lots of sites are popping up requiring users to login. When you need to do so, there's a bit more security than you might realize. You might be making a simple To-Do list, and might think:</p>
<blockquote>
<p>Security? Pfft, I'm not too worried about people's to-do lists being stolen.</p>
</blockquote>
<p>But what you didn't account for, is that all those username/password combinations a hacker just made off with? Yea, those are the same login's to important stuff, like <strong>e-mail</strong> , or <strong>bank accounts</strong> . Yikes!</p>]]></description>
			<content:encoded><![CDATA[<p>In the world of the web, lots of sites are popping up requiring users to login. When you need to do so, there's a bit more security than you might realize. You might be making a simple To-Do list, and might think:</p>
<blockquote>
<p>Security? Pfft, I'm not too worried about people's to-do lists being stolen.</p>
</blockquote>
<p>But what you didn't account for, is that all those username/password combinations a hacker just made off with? Yea, those are the same login's to important stuff, like <strong>e-mail</strong> , or <strong>bank accounts</strong> . Yikes!</p>
<h5>Worst Case Scenario</h5>
<p>Most users of the web don't think this hard about their own security, and even those that do, <em>it's too complicated to remember a unique username and password for every single web-site you visit</em> . And most of those users that don't know much about security also don't realize the need for using complicated passwords. So if you're collecting usernames and passwords, you need to design for the worst possible scenario:</p>
<p><em>Password: <code>password1</code> </em></p>
<h4>Just Hash It All</h4>
<p>So hopefully, the first thing you're thinking is that you shouldn't store your passwords in plain text. Good idea. You were thinking a hash, right? Because 2-way encryptions has it's own security problems. Once a user discovers the encryption key, they can decrypt every password you have. So let's hash everything.</p>
<p>There's plenty of debate about the best hashing algorithms, so for sake of simplicity, I'll just use md5*. But we're not going to use the straight output of the hash. <a href="http://www.codinghorror.com/blog/archives/000949.html" target="_blank">That's like storing plain text.</a> Instead, we'll make sure we use a nice salt.</p>
<p>Not any salt. Nothing like &quot;NaCLS4lt&quot;. No no, that <strong>also</strong> makes it too easy for hackers to precompute. Instead, we're going to generate a random salt for every single password. So even if they manage to crack just one password, they haven't gained the salt for the rest of the hashes.</p>
<p><img src="http://monstar.blazonco.com/images/blog/random_salt.jpg" alt="Use a random salt when producing the hash" /></p>
<pre><code>$salt = substr(md5(uniqid(rand(), true)), 0, $saltLen);</code>

</pre>
<p>We grab a nice, random string that gets hashed, and this garbled text becomes our salt.</p>
<pre><code>$hash = md5($salt . $plain);</code>

</pre>
<p>Optionally, here you could do some manipulation, like splitting the password in half, or adding some salt to the end. The same goes for this entire process. The more you can mix it up without trying to come up with your own hashing algorithm, the more non-standard your passwords become.</p>
<p>Now then, we need this salt for later use, or else we'll never be able to regenerate this hash when a user logs in! We're not ganna store it in a seperate database field called salt. That gives it straight away to the hacker. Instead, we attach it to the hash and make it seem like the whole long thing is the password.</p>
<p>Many sites will suggest simply concatenating them together, <code>$salt . $hash</code> . However, I figure, with such a constant location, while the hacker does have to deal with random salts, he doesn't have to worry about the location of it.</p>
<p><img src="http://monstar.blazonco.com/images/blog/insert_salt.jpg" alt="Insert the salt in the middle of the hash" /></p>
<p>So we take something that is constant with the user, but different enough to allow variations for storing the salt. I'll use simply the length of the password in plain text. If the password is 11 characters long, I insert the salt at character 11 of the hash. This way, it's different than a password that is 8 characters in length.</p>
<pre><code>return substr($hash,0,$saltStart).$salt.substr($hash,$saltStart+1);</code>

</pre>
<p>Now, this function you've been building up, all you need to do is add an optional argument for a hash. When a user tries to login, you look up the hash from the database, and supply their password attempt and hash to this function. Now check if the hash is supplied, and if so, calculate the position of the salt in the hash, grab the salt, and use that for your <code>md5($salt.$hash)</code> part. If the function returns a hash that equals the hash in the database, you have the correct password.</p>
<p><small>*I don't claim to be a cryptographer, so use at your own risk.</small></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=tyjTZHx8Gno:JFr-b3whilE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=tyjTZHx8Gno:JFr-b3whilE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=tyjTZHx8Gno:JFr-b3whilE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=tyjTZHx8Gno:JFr-b3whilE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=tyjTZHx8Gno:JFr-b3whilE:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Automagic Prefixes for Model Fields</title>
			<link>http://mcarthurgfx.com/blog/article/automagic-prefixes-for-model-fields</link>
			<comments>http://mcarthurgfx.com/blog/article/automagic-prefixes-for-model-fields#comments</comments>
			<pubDate>Tue, 23 Jun 2009 09:40:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[PHP]]></category>
			<guid>http://mcarthurgfx.com/blog/article/automagic-prefixes-for-model-fields</guid>
			<description><![CDATA[<p>Say we have a player model, and every field in <code>players</code>table is prepended with <em>player_</em>. For example, <code>player_username</code>, <code>player_email</code>, etc.</p>
<p>I'm personally not used to this database design, but I know plenty of people use it. When I work on projects that have this, I'm not particularly found of having to write:</p>
<pre><code>
$p = new Player;
echo $p-&gt;player_username;</code></pre>
<p>I'd rather ditch the prepended part in all my PHP code.</p>
<pre><code>echo $p-&gt;username;</code></pre>]]></description>
			<content:encoded><![CDATA[<p>Say we have a player model, and every field in <code>players</code>table is prepended with <em>player_</em>. For example, <code>player_username</code>, <code>player_email</code>, etc.</p>
<p>I'm personally not used to this database design, but I know plenty of people use it. When I work on projects that have this, I'm not particularly found of having to write:</p>
<pre><code>
$p = new Player;
echo $p-&gt;player_username;</code></pre>
<p>I'd rather ditch the prepended part in all my PHP code.</p>
<pre><code>echo $p-&gt;username;</code></pre>
<h4>Use Accessors</h4>
<p>We can do this by <a href="http://mcarthurgfx.com/blog/article/overloading-objects-in-php">writing some __get and __set functions</a>:</p>
<pre><code>
public function __get($name) {
    $prepend = 'player_'.$name;
    if(isset($this-&gt;$prepend)) {
        return $this-&gt;$prepend;
    }
    return parent::__get($name);
}
public function __set($name, $value) {
    $prepend = 'player_'.$name;
    if(isset($this-&gt;$prepend)) {
        $this-&gt;$prepend = $value;
    } else {
        parent::__set($name, $value);
        //if no parent, you might want the default:
        //$this-&gt;$name = $value
    }
}</code></pre>
<p>Basically, <a href="http://mcarthurgfx.com/blog/article/overloading-objects-in-php">stated before</a>, these get called when you try to access a property that doesn't exist on the object.  So when we try to access <code>username</code>, we check if <code>player_username</code> exists, and if so, return that value.</p>
<h4>MY_Model: Easily extendable</h4>
<p>You could work this into a MY_Model class that extends Model, and then make all your models extend MY_Model.  If you wanted to do this, I'd say make a property of MY_Model called 'prefix', and use prefix in the accesors.  Then, in each sub-class, all you need to do is define the prefix.</p>
<pre><code>
class MY_Model extends Model {
    protected $prefix;
    public function __get($name) {
        $prepend = $this-&gt;prefix.$name;
        //...
    }   
}</code></pre>
<pre><code>
class Player_Model extends MY_Model {
    protected $prefix = 'player_'; 
}</code></pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ohZ8mpyicnQ:3CF2ClAXUME:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ohZ8mpyicnQ:3CF2ClAXUME:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=ohZ8mpyicnQ:3CF2ClAXUME:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ohZ8mpyicnQ:3CF2ClAXUME:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=ohZ8mpyicnQ:3CF2ClAXUME:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Copy Objects and Arrays with $unlink</title>
			<link>http://mcarthurgfx.com/blog/article/copy-objects-and-arrays-with-unlink</link>
			<comments>http://mcarthurgfx.com/blog/article/copy-objects-and-arrays-with-unlink#comments</comments>
			<pubDate>Wed, 17 Jun 2009 10:00:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Javascript]]></category>
			<guid>http://mcarthurgfx.com/blog/article/copy-objects-and-arrays-with-unlink</guid>
			<description><![CDATA[<p>Basically, if you don't know what happens when you have multiple variables pointing to the same Object or Array, then check out this <a href="http://james.padolsey.com/javascript/deep-copying-of-objects-and-arrays/" target="_blank">quick and dirty article</a> and read the first half or so. Or if you don't want to bother, I'll give you a snippet to paste into Firebug.</p>
<pre><code><br />
var a = ['one','b',3,false];<br />
var b = a;<br />
a[1] = 'BEEEE';<br />
console.log(b[1]);</code>
<br />
</pre>]]></description>
			<content:encoded><![CDATA[<p>Basically, if you don't know what happens when you have multiple variables pointing to the same Object or Array, then check out this <a href="http://james.padolsey.com/javascript/deep-copying-of-objects-and-arrays/" target="_blank">quick and dirty article</a> and read the first half or so. Or if you don't want to bother, I'll give you a snippet to paste into Firebug.</p>
<pre><code>
var a = ['one','b',3,false];
var b = a;
a[1] = 'BEEEE';
console.log(b[1]);</code>

</pre>
<h4>Reference, pointer, whatever</h4>
<p>Caught on to what was happening there? We made one array, then assigned that array to another variable. That variable simply points at the same array, it's not copied. Now, when we change the array that's assigned a, we find the results of the change appearing b also.</p>
<p>This is because Javascript assigns complex types (notably Objects and Arrays (Functions and Strings count too, but they're immutable, so it doesn't matter)) by pointers. Usually called pass by reference, there might be some argument over the proper verbage. Ultimately, it doesn't matter much what you call it when you talk to yourself. It just matters that you understand what happens.</p>
<h4>Making Distinct Copies</h4>
<p>Now, sometimes, you may want a copy of the array or object instead of a reference, so if the original gets modified, your copy stays out of that sometimes confusing mess. There are a couply ways of copying an array or object, but what matters here, is that if one of the values is itself an array or object, you'll need to make a copy of that as well. Otherwise you'll get pointers in your facade of a copied object.</p>
<h5>$unlink</h5>
<p>The MooTools Core (1.2.2 as of writing) provides a function by the name of $unlink that solves this issue for us. Provide an array or object as an argument of $unlink, and it will return a copy that has been checked to make sure it has no back references. Let's do so to our original example.</p>
<pre><code>
var a = ['one','b',3,false];
var b = $unlink(a);
a[1] = 'BEEEE';
console.log(b[1]);</code>

</pre>
<p>See? They're different.  Go ahead and play with making arrays and objects that contain nested objects, and see what happens.  Then you'll see the power that $unlink gives you.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=yLydKR7o3d4:54LyiAfvH1A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=yLydKR7o3d4:54LyiAfvH1A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=yLydKR7o3d4:54LyiAfvH1A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=yLydKR7o3d4:54LyiAfvH1A:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=yLydKR7o3d4:54LyiAfvH1A:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Form Accessibility - Try Out Your Own</title>
			<link>http://mcarthurgfx.com/blog/article/form-accessibility-try-out-your-own</link>
			<comments>http://mcarthurgfx.com/blog/article/form-accessibility-try-out-your-own#comments</comments>
			<pubDate>Wed, 10 Jun 2009 09:30:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Accessibility,Standards]]></category>
			<guid>http://mcarthurgfx.com/blog/article/form-accessibility-try-out-your-own</guid>
			<description><![CDATA[<p>With web standards being all the rage, and accessibility being a major driving factor in people adopting standards, you might be surprised to actually check out the accessibility of web-sites.&nbsp; After watching <a href="http://www.youtube.com/watch?v=AmUPhEVWu_E" target="_blank">a video of a blind user using Jaws</a> , I figured to give using a <a href="http://www.nvda-project.org/" target="_blank">screen reader</a> a try just to see if I could understand it any better.&nbsp; I ran into a couple problematic areas; what caught my attention first was the use of <strong>forms</strong> .</p>]]></description>
			<content:encoded><![CDATA[<p>With web standards being all the rage, and accessibility being a major driving factor in people adopting standards, you might be surprised to actually check out the accessibility of web-sites. After watching <a href="http://www.youtube.com/watch?v=AmUPhEVWu_E" target="_blank">a video of a blind user using Jaws</a> , I figured to give using a <a href="http://www.nvda-project.org/" target="_blank">screen reader</a> a try just to see if I could understand it any better. I ran into a couple problematic areas; what caught my attention first was the use of <strong>forms</strong> .</p>
<h4>When Things Were Right</h4>
<p>When a form was built properly, I could easily understand what inputs a form had, and what input I had tabbed to. Quite simply, <em>there were 2 tags the specifically improved the accessibility of the form</em> for my screen reader: <code>legend</code> and <code>label</code> .</p>
<pre><code>
&lt;fieldset&gt;
    &lt;legend&gt;Personal&lt;/legend&gt;
    ...
&lt;/fieldset&gt;</code>

</pre>
<p>When I tabbed to an <code>input</code> that was within a <code>fieldset</code> , and that <code>fieldset</code> had a <code>legend</code> , it would tell me. The above would read to me: &quot;Personal grouping.&quot; So if this <code>fieldset</code> wrapped up inputs like your name, telephone, and e-mail address, it would remind me each time that this <code>input</code> was part of the &quot;Personal grouping&quot;, so I knew I hadn't tabbed to a new <code>fieldset</code> . Good.</p>
<pre><code>
&lt;label&gt;
    &lt;input name=&quot;personal:name&quot; type=&quot;text&quot; /&gt;
    &lt;span&gt;Name&lt;/span&gt;
&lt;/label&gt;</code>

</pre>
<p>For specific inputs, having a <code>label</code> did exactly as we would hope. I tabbed to the <code>input</code> , and it read the <code>label</code> and <code>input</code> type: &quot;Name, text.&quot; It specifically worked with the above example, when the <code>input</code> was inside a <code>label</code> . It would read the rest of the text inside the <code>label</code> .</p>
<h4>When Things Sucked</h4>
<p>I visited a few other sites that seemed to be using standards, and found that their forms performed far worse. It showed that <em>using the correct structure for forms is actually very important</em> . When a form used a simple paragraph before an input, with no <code>label</code> , guess what happened? Yep, it skipped it. When I tabbed to an <code>input</code> , it would just read me: &quot;Text&quot;. Hey, great. Any text? You got it: poop.</p>
<p>Yea, not good.</p>
<h5>Even worse</h5>
<p>Even if someone managed to make up information for these fields, or perhaps, say they did have labels on them, one more form feature that screwed my experience using a screen reader: <strong>captcha</strong> . Some implementations simply had an image above the input, with no alt tag, no possible way for me to ever prove I'm a human being. Minus one call to action.</p>
<p><img src="http://monstar.blazonco.com/images/blog/viget_form_accessibility.jpg" alt="Accessibility Don'ts" /></p>
<h4>Try Out Your Own</h4>
<p>I'd suggest grabbing <a href="http://www.nvda-project.org/" target="_blank">NVDA</a> , and surfing your site, and pay attention to your forms. See if the way you made them makes sense to a screen reader. And then visit some of your favorite sites, try out their forms, and compare with their markup. It's quite enlightening.</p>
<p>This leads to me to show the mark-up we use at <a href="http://www.blazonco.com" target="_blank">Blazonco</a> , which does work just fine with a screen reader, in another post soon.</p>
<p>Do any of you have any form accessibility tips beyond the basics?  For example, how would you include some description text that isn't really the label (ex: Your password must be more than 6 characters.)</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=GdrsBdqUID8:ZhJC0m_RIx4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=GdrsBdqUID8:ZhJC0m_RIx4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=GdrsBdqUID8:ZhJC0m_RIx4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=GdrsBdqUID8:ZhJC0m_RIx4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=GdrsBdqUID8:ZhJC0m_RIx4:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Universal IE6 Stylesheet: A Step Backwards</title>
			<link>http://mcarthurgfx.com/blog/article/universal-ie6-stylesheet-a-step-backwards</link>
			<comments>http://mcarthurgfx.com/blog/article/universal-ie6-stylesheet-a-step-backwards#comments</comments>
			<pubDate>Tue, 26 May 2009 08:00:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Standards]]></category>
			<guid>http://mcarthurgfx.com/blog/article/universal-ie6-stylesheet-a-step-backwards</guid>
			<description><![CDATA[<p>As many have noted, there's many opinions on how to handle the Internet Explorer 6 monster.&nbsp; <a href="http://forabeautifulweb.com/" target="_blank">For a beautiful web</a> just suggested his solution: <a href="http://forabeautifulweb.com/blog/about/universal_internet_explorer_6_css/" target="_blank">one stylesheet to rule them all</a> . It's completely ridiculous, and I'm suprised to see other professionals agreeing.</p>]]></description>
			<content:encoded><![CDATA[<p>As many have noted, there's many opinions on how to handle the Internet Explorer 6 monster.&nbsp; <a href="http://forabeautifulweb.com/" target="_blank">For a beautiful web</a> just suggested his solution: <a href="http://forabeautifulweb.com/blog/about/universal_internet_explorer_6_css/" target="_blank">one stylesheet to rule them all</a> . It's completely ridiculous, and I'm suprised to see other professionals agreeing.</p>
<h4>A Relatively Capable Browser</h4>
<p>IE6, while certainly layout-challenged, can handle basic layout, and still decent color, background, type and image support.&nbsp; People using Internet Explorer 6 are used to web pages looking decent.&nbsp; Websites looking plain black and white with no design all of a sudden will make people think your site is broken (or just sucks).&nbsp; And one principle of web standards is that <em>they shouldn't think your website is broken</em> .</p>
<p>Sure you could change the text colors, you say. But c'mon, its really not that bad to remove the problematic CSS from IE6.&nbsp; <a href="http://boagworld.com/design/a-demonstration-of-graded-browser-support" target="_blank">Boagworld did a good job</a> of showing how easy it is to do, and it still looks pretty decent.</p>
<h4>The Standards Stance</h4>
<p><strong>I'll be the first to condemn IE6</strong> to the farthest depths of the trash can. I hate the bugger.&nbsp; But as a web developer, I also strongly believe in <a href="http://www.alistapart.com/articles/understandingprogressiveenhancement/" target="_blank">progressive enhancement</a> , and giving each browser what it can handle.</p>
<p>Sometimes I'm asked to make something look the same in IE6 as Firefox 3, and while I do it (I need to eat), I strongly disagree with it.&nbsp; My boss expects some whining from my side of the office when I'm told. I agree more with <a href="http://developer.yahoo.com/yui/articles/gbs/" target="_blank">Yahoo's graded browser support</a> .</p>
<p>The plain stylesheet to IE6 turns it into a cousin of Lynx, and certainly under-utilizes the power that IE6 does have.&nbsp; Ultimately, <strong>it goes against the point of standards</strong> .&nbsp; Why bother at all, if you aren't going to treat everyone the way they can.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=112iCdk8l2w:xGiEuP3PnpU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=112iCdk8l2w:xGiEuP3PnpU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=112iCdk8l2w:xGiEuP3PnpU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=112iCdk8l2w:xGiEuP3PnpU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=112iCdk8l2w:xGiEuP3PnpU:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Get Class of an Instance</title>
			<link>http://mcarthurgfx.com/blog/article/get-class-of-an-instance</link>
			<comments>http://mcarthurgfx.com/blog/article/get-class-of-an-instance#comments</comments>
			<pubDate>Fri, 08 May 2009 11:00:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Javascript]]></category>
			<guid>http://mcarthurgfx.com/blog/article/get-class-of-an-instance</guid>
			<description><![CDATA[<p>Have you ever wanted to get the class name of an object, maybe to check what instance it is of, or maybe to use the name for something? I was in need of exactly that, so I set out to do so last night. I started by asking <a href="http://stackoverflow.com/questions/837729/how-to-get-the-name-of-a-mootools-class-from-within" target="_blank">Stack Overflow</a> , and no one gave me an answer, so I pondered about it a bit. I started paying attention to the <a href="http://mootools.net/docs/core/Native/Hash" target="_blank">Hash</a> object.</p>
<p>I knew that inside a class function, this.constructor would reveal the function that makes new intances of that class. But that function is anonymous, so I couldn't ask for the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/name" target="_blank">Function.name</a> property. But! But,<strong> if I have a value, I can check an object for the key of that value.</strong></p>]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to get the class name of an object, maybe to check what instance it is of, or maybe to use the name for something? I was in need of exactly that, so I set out to do so last night. I started by asking <a href="http://stackoverflow.com/questions/837729/how-to-get-the-name-of-a-mootools-class-from-within" target="_blank">Stack Overflow</a> , and no one gave me an answer, so I pondered about it a bit. I started paying attention to the <a href="http://mootools.net/docs/core/Native/Hash" target="_blank">Hash</a> object.</p>
<p>I knew that inside a class function, this.constructor would reveal the function that makes new intances of that class. But that function is anonymous, so I couldn't ask for the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/name" target="_blank">Function.name</a> property. But! But,<strong> if I have a value, I can check an object for the key of that value.</strong></p>
<pre><code>
var Poop = new Class({
    get_class: function() {
        return $H(window).keyOf(this.constructor);
    }   
});</code>

</pre>
<p>This made me super excited, cause now I can build an interface that uses the class name for a particular process. And when I decided to write about it, I figured I'd make sure this method worked in all cases. And realized a case where this wouldn't work: Drag.Move (Obj.Anything, actually).</p>
<h4>Finding in Namespaces</h4>
<p>The original function scans the window object for the class that has been declared. But what if you created the class inside some namespace? You could change the function to check the Hash of the namespace, but I didn't like that. <em>So I pulled together a new Hash function that searchs a Hash recursively for a ke</em> y (keyOf only goes one level).</p>
<pre><code>
Hash.implement({
    findKey: function(key) {  
        var val = this.keyOf(key);
        if(val) return val;
        for(var prop in this) {   
            if(this.hasOwnProperty(prop) &amp;&amp; typeof this[prop] == 'object') {
                val = $H(this[prop]).findKey(key);
                if(val) {
                 return this.findKey(this[prop]) + '.' + val;
                }
            }
        }
    }   
});</code>

</pre>
<h4>A Class Extra</h4>
<p>Now equipped with Hash.findKey, I altered the get_class function to work anywhere. This is a class that you can include in your Implements option for any new Class:</p>
<pre><code>
var GetClass = new Class({
    get_class: function() {
        return $H(window).keyOf(this.constructor);
    }   
});</code>

</pre>
<p>With the Hash method, and this new class included in your scripts, this simple example works out:</p>
<pre><code>
var Foo = {};
Foo.Bar = new Class({ 
    Implements: [GetClass]
});
var a = new Foo.Bar();
a.get_class(); //returns 'Foo.Bar'
</code>

</pre>
<p>I'd love to hear any uses you might have for this in the <a href="http://mcarthurgfx.com/blog/article/get-class-of-an-instance#comments">comments</a> .</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ZLGc2bWaqPY:qFyQ_gJ8Jak:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ZLGc2bWaqPY:qFyQ_gJ8Jak:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=ZLGc2bWaqPY:qFyQ_gJ8Jak:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=ZLGc2bWaqPY:qFyQ_gJ8Jak:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=ZLGc2bWaqPY:qFyQ_gJ8Jak:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>Use CSS Borders for 3D Effects</title>
			<link>http://mcarthurgfx.com/blog/article/use-css-borders-for-3d-effects</link>
			<comments>http://mcarthurgfx.com/blog/article/use-css-borders-for-3d-effects#comments</comments>
			<pubDate>Wed, 29 Apr 2009 08:55:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[CSS]]></category>
			<guid>http://mcarthurgfx.com/blog/article/use-css-borders-for-3d-effects</guid>
			<description><![CDATA[<p><img src="http://monstar.blazonco.com/images/blog/bz_buttons.png" alt="Buttons with 3D Bevel Effect" /></p>
<p>Recently, I've been more in favor of using the browsers rendering instead of background images to achieve looks, since that <strong>reduces bandwidth and loading times</strong> , and also <strong>increases maintainability</strong> . I used to slice images that would give something a shadow or button type of a look, but have moved more towards just making the browser do it. I wanted to share some examples of effects and how easy it is to do so.</p>]]></description>
			<content:encoded><![CDATA[<p>Recently, I've been more in favor of using the browsers rendering instead of background images to achieve looks, since that <strong>reduces bandwidth and loading times</strong> , and also <strong>increases maintainability</strong> . I used to slice images that would give something a shadow or button type of a look, but have moved more towards just making the browser do it. I wanted to share some examples of effects and how easy it is to do so.</p>
<h4>3D Buttons</h4>
<p>As a smaller example, I'll show the buttons I put together for the Blazonco admin post index page. Rather simple, but I wanted to achieve that effect you've seen in older buttons. You know, where the top part is light than the bottom, so it looks slightly raised out of the application. And then on hover, I swap the border colors, giving the look of being pushed in.</p>
<p><img src="http://monstar.blazonco.com/images/blog/bz_buttons.png" alt="Buttons with 3D Bevel Effect" /></p>
<p>I threw a darker color on the bottom and right sides. The above picture shows normal (left) and hover (right). Of course, Print Screen hides the cursor (which I found weird). And here's the relevant CSS:</p>
<pre><code>
a.button {
	background-color:#fff;
	border-width:1px;
	border-style:solid;
	border-bottom-color:#aaa;
	border-right-color:#aaa;
	border-top-color:#ddd;
	border-left-color:#ddd;
	border-radius:3px;
	-moz-border-radius:3px;
	-webkit-border-radius:3px;
}</code>

</pre>
<p><em>Having it in CSS allowed me to easily test out the results</em> , and tweak the color slightly as I decided one side was too dark or too light. And I also was able to easily experiment with how round I wanted the button. When using images for all this, you'd have to make the changes in Photoshop, and save it and upload it again. So a major gain is in <strong>how easy it is to maintain</strong> .</p>
<h4>Shadows<br /></h4>
<p>I had the joy of turning a comp with mutliple rounded corner boxes and shadows and the like into a working web-site not long ago. I originally thought that these boxes would also need to be expandable, and I wondered how to achieve this in a feasible way. I settled on using various CSS3 techniques instead of image slices with <a href="http://www.alistapart.com/articles/slidingdoors/" target="_blank">sliding door</a> techniques.</p>
<p>The end result was as such:</p>
<p><img src="http://monstar.blazonco.com/images/blog/ibank_borders.png" alt="Boxes with a Pseudo-Shadow" /></p>
<p>In the boxes, I used a gradiant slice for the background, and then used only border and border-radius to obtain a kind of 3D look. Here's the CSS:</p>
<pre><code>
.module {
	background:#fcfcfc url('images/module.png') repeat-x left bottom;
	border:1px solid #ccc;
	border-bottom:2px solid #bbb;
	border-top:1px solid #ddd;
	border-radius:10px;
	-webkit-border-radius:10px;
	-moz-border-radius:10px;
}</code>

</pre>
<p>By making the border bigger and darker on the bottom, and lighter and thinner on the sides and top, I gave it a pseudo-shadow. The benefits of this over an image is that it only took 1 element to style (the div), and it could easily expand in any direction without running out of image.</p>
<p>Since it was using CSS3 techniques, it was squared in Internet Explorer, but continued to look good. This is an important factor of <a href="http://www.alistapart.com/articles/progressiveenhancementwithcss" target="_blank">progressive enchancement</a> , since I made sure to use CSS that looked nice in older browsers.</p>
<h5>CSS Feature Detection?</h5>
<p>One last rule I would have liked to add but never did was using Safari's drop shadow property. That would have achieved an even nicer looking shadow in Safari. The reason holding me back, was that I'd already used border's to accomplish this effect, and didn't want to try to remove them for Safari. This would have required some Safari CSS hacks, since I currently don't know of a way to do CSS feature detection.</p>
<p>It'd be cool if you could do something as such (I'm going to steal some Javascript syntax):</p>
<pre><code>
if(-webkit-box-shadow) {
	.module {
		border:none;
		-webkit-box-shadow:5px 2px 2px #bbb;
	}
}</code>

</pre>
<p>Do any of you <a href="http://mcarthurgfx.com/blog/article/use-css-borders-for-3d-effects#comments">have any suggestions</a> on how to properly achieve that with current technologies? And I'm not interested in server-side sniffing. That's obvious, and sub-optimal.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=OJwrnGnWiZ0:x_Lnv6FdIDM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=OJwrnGnWiZ0:x_Lnv6FdIDM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=OJwrnGnWiZ0:x_Lnv6FdIDM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=OJwrnGnWiZ0:x_Lnv6FdIDM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=OJwrnGnWiZ0:x_Lnv6FdIDM:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				<item>
			<title>New Class Initialize in Mootools 1.2.2</title>
			<link>http://mcarthurgfx.com/blog/article/new-class-initialize-in-mootools-1-2-2</link>
			<comments>http://mcarthurgfx.com/blog/article/new-class-initialize-in-mootools-1-2-2#comments</comments>
			<pubDate>Fri, 24 Apr 2009 11:08:00 -0700</pubDate>
			<dc:creator>Sean</dc:creator>
						<category><![CDATA[Javascript]]></category>
			<guid>http://mcarthurgfx.com/blog/article/new-class-initialize-in-mootools-1-2-2</guid>
			<description><![CDATA[<p>Just a quickie: I was browsing the new Class script of <a href="http://mootools.net/blog/2009/04/23/mootools-122-and-the-new-mootools-more/" target="_blank">Mootools 1.2.2</a> , to learn about all the changes (which are quite awesome), and I hope to rework my <a href="http://mcarthurgfx.com/blog/article/getting-private-variables-in-a-mootools-class">Privates Mutator</a> real soon to work with the new way of things. <strong>I noticed this immediately:</strong></p>
<pre><code>if (params instanceof Function) params = {initialize: params};</code>

</pre>]]></description>
			<content:encoded><![CDATA[<p>Just a quickie: I was browsing the new Class script of <a href="http://mootools.net/blog/2009/04/23/mootools-122-and-the-new-mootools-more/" target="_blank">Mootools 1.2.2</a> , to learn about all the changes (which are quite awesome), and I hope to rework my <a href="http://mcarthurgfx.com/blog/article/getting-private-variables-in-a-mootools-class">Privates Mutator</a> real soon to work with the new way of things. <strong>I noticed this immediately:</strong></p>
<pre><code>if (params instanceof Function) params = {initialize: params};</code>

</pre>
<p>If you only pass in a <em>function</em> , instead of an Object with functions in it, then that function will be the <code>initialize</code> (or constructor) of your class.</p>
<p>So instead of:</p>
<pre><code>
var Test = new Class({
    initialize:function() {
        console.log('testing');
    }
});</code>

</pre>
<p>you can now write:</p>
<pre><code>
var Test = new Class(function() {
    console.log('test');
});</code>

</pre>
<p>I'm not quite sure of a good use for this, but if you just needed a quickie class that you just want to instantiate and that's it, then this is for you!</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=EV7AvtJewpI:NAuX6A6NMs4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=EV7AvtJewpI:NAuX6A6NMs4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=EV7AvtJewpI:NAuX6A6NMs4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/mcarthurgfx?a=EV7AvtJewpI:NAuX6A6NMs4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/mcarthurgfx?i=EV7AvtJewpI:NAuX6A6NMs4:F7zBnMyn0Lo" border="0"></img></a>
</div>]]></content:encoded>
		</item>
				
	</channel>
</rss>
