<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monkey Magician &#187; framework</title>
	<atom:link href="http://www.monkeymagician.co.uk/tag/framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.monkeymagician.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 16 Jun 2010 12:14:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Default Event Handlers in MooTools 1.2 Classes</title>
		<link>http://www.monkeymagician.co.uk/2008/08/31/default-events-in-mootools-12-classes/</link>
		<comments>http://www.monkeymagician.co.uk/2008/08/31/default-events-in-mootools-12-classes/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 14:33:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[options]]></category>

		<guid isPermaLink="false">http://www.monkeymagician.co.uk/2008/08/31/default-events-in-mootools-12-classes/</guid>
		<description><![CDATA[I recently started converting some UI components I created in MooTools 1.1 into 1.2 versions to use on a new project. For a point release, I&#8217;m surprised how different a lot of the MooTools syntax is in the latest version. One thing that took a bit of getting used to was how inheritance has changed, [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started converting some UI components I created in MooTools 1.1 into 1.2 versions to use on a new project. For a point release, I&#8217;m surprised how different a lot of the MooTools syntax is in the latest version. One thing that took a bit of getting used to was how inheritance has changed, and the knock on effects when using Options and Effects in my classes.<span id="more-12"></span></p>
<p>In the MooTools 1.1 version I had a base class, &#8216;Widget&#8217; which I would extend as below:</p>
<p class="code">var DialogBox = Widget.extend({ &#8230; });</p>
<p>Widget implements both Options and Events which allowed me to create a set of events the widget can fire, handlers for which can be added through options, as such:</p>
<pre class="code">var DialogBox = Widget.extend({
  options : {
    onCancel : this.close.bind(this)
  }
  ...
});</pre>
<p>Because extend is a method of Widget, its &#8216;this&#8217; is the object itself and, provided there is a close method, the event handler for &#8216;cancel&#8217; is set up.</p>
<p>MooTools 1.2 introduces a new syntax for extending objects:</p>
<pre class="code">
var DialogBox = new Class({
  Extends : Widget,

  options : {
    onCancel : this.close.bind(this)
  },
  ...
});</pre>
<p>Now, the &#8216;this&#8217; is actually the window object so the cancel event is actually handled by the window.close method &#8211; not quite the functionality intended!</p>
<p>After digging around in the MooTools code, in particular the Request.HTML class, I found what appears to be the only way to default events in options. By setting the option before calling setOptions (if it isn&#8217;t already set), the event handler is correctly assigned:</p>
<pre class="code">
var DialogBox = new Class({
  Extends : Widget,

  options : {
    ...
  },

  initialize: function(options) {
    options.onCancel = options.onCancel || this.close.bind(this);
    this.setOptions(options);
  },
  ...
});</pre>
<p>The binding is now done on instantiation so the correct close method is assigned as the cancel event handler.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.monkeymagician.co.uk/2008/08/31/default-events-in-mootools-12-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
