Base.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: base Base.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>base&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_base.html">base</a>
&gt; Base.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre> <span class="c">/**</span>
<span class="c"> * Base class support for objects requiring</span>
<span class="c"> * managed attributes and acting as event targets</span>
<span class="c"> *</span>
<span class="c"> * @module base</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">L</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">,</span>
<span class="nx">O</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Object</span><span class="o">,</span>
<span class="nx">SEP</span> <span class="o">=</span> <span class="s2">&quot;:&quot;</span><span class="o">,</span>
<span class="nx">DESTROY</span> <span class="o">=</span> <span class="s2">&quot;destroy&quot;</span><span class="o">,</span>
<span class="nx">INIT</span> <span class="o">=</span> <span class="s2">&quot;init&quot;</span><span class="o">,</span>
<span class="nx">VALUE</span> <span class="o">=</span> <span class="s2">&quot;value&quot;</span><span class="o">,</span>
<span class="nx">INITIALIZED</span> <span class="o">=</span> <span class="s2">&quot;initialized&quot;</span><span class="o">,</span>
<span class="nx">DESTROYED</span> <span class="o">=</span> <span class="s2">&quot;destroyed&quot;</span><span class="o">,</span>
<span class="nx">INITIALIZER</span> <span class="o">=</span> <span class="s2">&quot;initializer&quot;</span><span class="o">,</span>
<span class="nx">DESTRUCTOR</span> <span class="o">=</span> <span class="s2">&quot;destructor&quot;</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">ETP</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Target</span><span class="o">.</span><span class="nx">prototype</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Provides a base class for managed attribute based</span>
<span class="c"> * objects, which handles the chaining of initializer and destructor methods</span>
<span class="c"> * across the hierarchy during init and destroy lifecycle methods and </span>
<span class="c"> * handles automatic configuration of registered Attributes, through </span>
<span class="c"> * the static ATTRS property.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> *</span>
<span class="c"> * &lt;p&gt;The Base class also handles prefixing of event types with the static NAME </span>
<span class="c"> * property for all events fired from instances of classes derived from Base.&lt;/p&gt;</span>
<span class="c"> *</span>
<span class="c"> * @constructor</span>
<span class="c"> * @class Base</span>
<span class="c"> * @uses Attribute</span>
<span class="c"> *</span>
<span class="c"> * @param {Object} config Object literal of configuration property name/value pairs</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">Base</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;constructor called&#39;</span><span class="o">,</span> <span class="s1">&#39;life&#39;</span><span class="o">,</span> <span class="s1">&#39;base&#39;</span><span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Attribute</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="k">this</span><span class="o">.</span><span class="nx">init</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Name string to be used to identify instances of </span>
<span class="c"> * this class, for example in prefixing events.</span>
<span class="c"> *</span>
<span class="c"> * Classes extending Base, should define their own</span>
<span class="c"> * static NAME property.</span>
<span class="c"> *</span>
<span class="c"> * @property NAME</span>
<span class="c"> * @type String</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">Base</span><span class="o">.</span><span class="nx">NAME</span> <span class="o">=</span> <span class="s1">&#39;base&#39;</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * Object literal defining the set of attributes which</span>
<span class="c"> * will be available for instances of this class, and </span>
<span class="c"> * how they are configured. See Attributes addAtt method</span>
<span class="c"> * for a description of configuration options available </span>
<span class="c"> * for each attribute.</span>
<span class="c"> *</span>
<span class="c"> * @property ATTRS</span>
<span class="c"> * @type Object</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">Base</span><span class="o">.</span><span class="nx">ATTRS</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Flag indicating whether or not this object</span>
<span class="c"> * has been through the init lifecycle phase.</span>
<span class="c"> *</span>
<span class="c"> * @attribute initialized</span>
<span class="c"> * @readOnly</span>
<span class="c"> * @default false</span>
<span class="c"> * @type boolean</span>
<span class="c"> */</span>
<span class="nx">intialized</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">readOnly</span><span class="o">:</span><span class="kc">true</span><span class="o">,</span>
<span class="nx">value</span><span class="o">:</span><span class="kc">false</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Flag indicating whether or not this object</span>
<span class="c"> * has been through the destroy lifecycle phase.</span>
<span class="c"> *</span>
<span class="c"> * @attribute destroyed</span>
<span class="c"> * @readOnly</span>
<span class="c"> * @default false</span>
<span class="c"> * @type boolean</span>
<span class="c"> */</span>
<span class="nx">destroyed</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">readOnly</span><span class="o">:</span><span class="kc">true</span><span class="o">,</span>
<span class="nx">value</span><span class="o">:</span><span class="kc">false</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">_instances</span> <span class="o">=</span> <span class="o">{};</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Builds a constructor function (class) from the</span>
<span class="c"> * main function, and array of extension functions (classes)</span>
<span class="c"> * provided.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * The cfg object literal supports the following properties</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;dl&gt;</span>
<span class="c"> * &lt;dt&gt;dynamic {boolean}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;</span>
<span class="c"> * &lt;p&gt;If true, a completely new class</span>
<span class="c"> * is created which extends the main class, and acts as the </span>
<span class="c"> * host on which the extension classes are augmented.&lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;If false, the extensions classes are augmented directly to</span>
<span class="c"> * the main class, modifying the main classes prototype.&lt;/p&gt;</span>
<span class="c"> * &lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;aggregates {String[]}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;An array of static property names, which will get aggregated</span>
<span class="c"> * on to the built class in addition to the default properties build </span>
<span class="c"> * will always aggregate - &quot;ATTRS&quot; and &quot;PLUGINS&quot;, as defined by </span>
<span class="c"> * Base.build.AGGREGATES&lt;/dd&gt;</span>
<span class="c"> * &lt;/dl&gt;</span>
<span class="c"> *</span>
<span class="c"> * @method build</span>
<span class="c"> * @static</span>
<span class="c"> * @param {Function} main The main class on which to base the built class</span>
<span class="c"> * @param {Function[]} extensions The set of extension classes which will be</span>
<span class="c"> * augmented/aggregated to the built class.</span>
<span class="c"> * @param {Object} cfg</span>
<span class="c"> */</span>
<span class="nx">Base</span><span class="o">.</span><span class="nx">build</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">main</span><span class="o">,</span> <span class="nx">extensions</span><span class="o">,</span> <span class="nx">cfg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">build</span> <span class="o">=</span> <span class="nx">Base</span><span class="o">.</span><span class="nx">build</span><span class="o">,</span>
<span class="nx">builtClass</span><span class="o">,</span>
<span class="nx">extClass</span><span class="o">,</span>
<span class="nx">aggregates</span><span class="o">,</span>
<span class="nx">dynamic</span><span class="o">,</span>
<span class="nx">key</span> <span class="o">=</span> <span class="nx">main</span><span class="o">.</span><span class="nx">NAME</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">cfg</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">aggregates</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">.</span><span class="nx">aggregates</span><span class="o">;</span>
<span class="nx">dynamic</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">.</span><span class="nx">dynamic</span><span class="o">;</span>
<span class="o">}</span>
<span class="c">// Create dynamic class or just modify main class</span>
<span class="c"></span> <span class="nx">builtClass</span> <span class="o">=</span> <span class="o">(</span><span class="nx">dynamic</span><span class="o">)</span> <span class="o">?</span> <span class="nx">build</span><span class="o">.</span><span class="nx">_template</span><span class="o">(</span><span class="nx">main</span><span class="o">)</span> <span class="o">:</span> <span class="nx">main</span><span class="o">;</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">_yuibuild</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">id</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
<span class="nx">exts</span> <span class="o">:</span> <span class="o">[],</span>
<span class="nx">dynamic</span> <span class="o">:</span> <span class="nx">dynamic</span>
<span class="o">};</span>
<span class="nx">aggregates</span> <span class="o">=</span> <span class="o">(</span><span class="nx">aggregates</span><span class="o">)</span> <span class="o">?</span> <span class="nx">build</span><span class="o">.</span><span class="nx">AGGREGATES</span><span class="o">.</span><span class="nx">concat</span><span class="o">(</span><span class="nx">aggregates</span><span class="o">)</span> <span class="o">:</span> <span class="nx">build</span><span class="o">.</span><span class="nx">AGGREGATES</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="nx">extensions</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span>
<span class="nx">al</span> <span class="o">=</span> <span class="nx">aggregates</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span>
<span class="nx">i</span><span class="o">;</span>
<span class="c">// Shallow isolate aggregates</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">dynamic</span> <span class="o">&amp;&amp;</span> <span class="nx">aggregates</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">al</span><span class="o">;</span> <span class="nx">i</span><span class="o">++)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">aggregates</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">main</span><span class="o">,</span> <span class="nx">val</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">builtClass</span><span class="o">[</span><span class="nx">val</span><span class="o">]</span> <span class="o">=</span> <span class="nx">L</span><span class="o">.</span><span class="nx">isArray</span><span class="o">(</span><span class="nx">main</span><span class="o">[</span><span class="nx">val</span><span class="o">])</span> <span class="o">?</span> <span class="o">[]</span> <span class="o">:</span> <span class="o">{};</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">aggregate</span><span class="o">(</span><span class="nx">builtClass</span><span class="o">,</span> <span class="nx">main</span><span class="o">,</span> <span class="kc">true</span><span class="o">,</span> <span class="nx">aggregates</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">// Augment/Aggregate</span>
<span class="c"></span> <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">el</span><span class="o">;</span> <span class="nx">i</span><span class="o">++)</span> <span class="o">{</span>
<span class="nx">extClass</span> <span class="o">=</span> <span class="nx">extensions</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">aggregates</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">aggregate</span><span class="o">(</span><span class="nx">builtClass</span><span class="o">,</span> <span class="nx">extClass</span><span class="o">,</span> <span class="kc">true</span><span class="o">,</span> <span class="nx">aggregates</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">// Old augment</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">builtClass</span><span class="o">,</span> <span class="nx">extClass</span><span class="o">,</span> <span class="kc">true</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="m">1</span><span class="o">);</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">extClass</span><span class="o">);</span>
<span class="nx">key</span> <span class="o">=</span> <span class="nx">key</span> <span class="o">+</span> <span class="s2">&quot;:&quot;</span> <span class="o">+</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="nx">extClass</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">key</span><span class="o">;</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">hasImpl</span> <span class="o">=</span> <span class="nx">build</span><span class="o">.</span><span class="nx">_hasImpl</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">dynamic</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">NAME</span> <span class="o">=</span> <span class="nx">main</span><span class="o">.</span><span class="nx">NAME</span><span class="o">;</span>
<span class="nx">builtClass</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">constructor</span> <span class="o">=</span> <span class="nx">builtClass</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">builtClass</span><span class="o">;</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">Base</span><span class="o">.</span><span class="nx">build</span><span class="o">,</span> <span class="o">{</span>
<span class="nx">AGGREGATES</span> <span class="o">:</span> <span class="o">[</span><span class="s2">&quot;ATTRS&quot;</span><span class="o">,</span> <span class="s2">&quot;PLUGINS&quot;</span><span class="o">],</span>
<span class="nx">_template</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">main</span><span class="o">)</span> <span class="o">{</span>
<span class="k">function</span> <span class="nx">BuiltClass</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">BuiltClass</span><span class="o">.</span><span class="nx">superclass</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="nx">BuiltClass</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span><span class="o">,</span>
<span class="nx">l</span> <span class="o">=</span> <span class="nx">f</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">l</span><span class="o">;</span> <span class="nx">i</span><span class="o">++)</span> <span class="o">{</span>
<span class="nx">f</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">extend</span><span class="o">(</span><span class="nx">BuiltClass</span><span class="o">,</span> <span class="nx">main</span><span class="o">);</span>
<span class="k">return</span> <span class="nx">BuiltClass</span><span class="o">;</span>
<span class="o">},</span>
<span class="nx">_hasImpl</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">extClass</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span><span class="o">,</span>
<span class="nx">l</span> <span class="o">=</span> <span class="nx">f</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span>
<span class="nx">i</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">l</span><span class="o">;</span> <span class="nx">i</span><span class="o">++)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">f</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">===</span> <span class="nx">extClass</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">});</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Creates a new object instance, based on a dynamically created custom class.</span>
<span class="c"> * The custom class is created from the main class passed in as the first parameter </span>
<span class="c"> * along with the list of extension classes passed in</span>
<span class="c"> * as the second parameter using &lt;a href=&quot;#method_build&gt;Base.build&lt;/a&gt; </span>
<span class="c"> * with &quot;dynamic&quot; set to true. See the documentation for this method </span>
<span class="c"> * to see how the main class and extension classes are used.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * </span>
<span class="c"> * &lt;p&gt;Any arguments following the 2nd argument are passed as arguments to the </span>
<span class="c"> * constructor of the newly created class used to create the instance.&lt;/p&gt;</span>
<span class="c"> * </span>
<span class="c"> * @method create</span>
<span class="c"> * @static</span>
<span class="c"> *</span>
<span class="c"> * @param {Function} main The main class on which the instance it to be </span>
<span class="c"> * based. This class will be extended to create the class for the custom instance</span>
<span class="c"> * @param {Array} extensions The list of extension classes used to augment the</span>
<span class="c"> * main class with.</span>
<span class="c"> * @param {Any*} args Zero or more arguments to pass to the constructor of the </span>
<span class="c"> * newly created class, when creating the instance.</span>
<span class="c"> */</span>
<span class="nx">Base</span><span class="o">.</span><span class="nx">create</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">main</span><span class="o">,</span> <span class="nx">extensions</span><span class="o">,</span> <span class="nx">args</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="nx">Base</span><span class="o">.</span><span class="nx">build</span><span class="o">(</span><span class="nx">main</span><span class="o">,</span> <span class="nx">extensions</span><span class="o">,</span> <span class="o">{</span><span class="nx">dynamic</span><span class="o">:</span><span class="kc">true</span><span class="o">}),</span>
<span class="nx">cArgs</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">2</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="k">function</span> <span class="nx">F</span><span class="o">(){}</span>
<span class="nx">F</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">prototype</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">c</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">new</span> <span class="nx">F</span><span class="o">(),</span> <span class="nx">cArgs</span><span class="o">);</span>
<span class="o">};</span>
<span class="nx">Base</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Init lifecycle method, invoked during construction.</span>
<span class="c"> * Fires the init event prior to invoking initializers on</span>
<span class="c"> * the class hierarchy.</span>
<span class="c"> * </span>
<span class="c"> * @method init</span>
<span class="c"> * @final</span>
<span class="c"> * @chainable</span>
<span class="c"> * @param {Object} config Object literal of configuration property name/value pairs</span>
<span class="c"> */</span>
<span class="nx">init</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">config</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;init called&#39;</span><span class="o">,</span> <span class="s1">&#39;life&#39;</span><span class="o">,</span> <span class="s1">&#39;base&#39;</span><span class="o">);</span>
<span class="c">/**</span>
<span class="c"> * The name string to be used to identify </span>
<span class="c"> * this instance of object. </span>
<span class="c"> * @property name</span>
<span class="c"> * @type String</span>
<span class="c"> */</span>
<span class="k">this</span><span class="o">.</span><span class="nx">name</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">NAME</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Init event, fired prior to initialization. Invoking</span>
<span class="c"> * the preventDefault method on the EventFacade provided </span>
<span class="c"> * to subscribers will prevent initialization from occuring.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Subscribers to the after momemt of this event, will be notified</span>
<span class="c"> * after initialization of the object is complete (and therefore</span>
<span class="c"> * cannot prevent initialization).</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> *</span>
<span class="c"> * @event init</span>
<span class="c"> * @preventable _defInitFn</span>
<span class="c"> * @param {Event.Facade} e Event object</span>
<span class="c"> * @param config Object literal of configuration name/value pairs</span>
<span class="c"> */</span>
<span class="k">this</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="nx">INIT</span><span class="o">,</span> <span class="o">{</span>
<span class="nx">queuable</span><span class="o">:</span><span class="kc">false</span><span class="o">,</span>
<span class="nx">defaultFn</span><span class="o">:</span><span class="k">this</span><span class="o">.</span><span class="nx">_defInitFn</span>
<span class="o">});</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">INIT</span><span class="o">,</span> <span class="nx">config</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Destroy lifecycle method. Fires the destroy</span>
<span class="c"> * event, prior to invoking destructors for the</span>
<span class="c"> * class hierarchy.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Subscribers to the destroy</span>
<span class="c"> * event can preventDefault to prevent destruction</span>
<span class="c"> * from proceeding.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * @method destroy</span>
<span class="c"> * @final</span>
<span class="c"> * @chainable</span>
<span class="c"> */</span>
<span class="nx">destroy</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;destroy called&#39;</span><span class="o">,</span> <span class="s1">&#39;life&#39;</span><span class="o">,</span> <span class="s1">&#39;base&#39;</span><span class="o">);</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Destroy event, fired prior to destruction. Invoking</span>
<span class="c"> * the preventDefault method on the EventFacade provided </span>
<span class="c"> * to subscribers will prevent destruction from proceeding.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Subscribers to the after momemt of this event, will be notified</span>
<span class="c"> * after destruction is complete (and as a result cannot prevent</span>
<span class="c"> * destruction).</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * @event destroy</span>
<span class="c"> * @preventable _defDestroyFn</span>
<span class="c"> * @param {Event.Facade} e Event object</span>
<span class="c"> */</span>
<span class="k">this</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="nx">DESTROY</span><span class="o">,</span> <span class="o">{</span>
<span class="nx">queuable</span><span class="o">:</span><span class="kc">false</span><span class="o">,</span>
<span class="nx">defaultFn</span><span class="o">:</span> <span class="k">this</span><span class="o">.</span><span class="nx">_defDestroyFn</span>
<span class="o">});</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">DESTROY</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Default init event handler</span>
<span class="c"> *</span>
<span class="c"> * @method _defInitFn</span>
<span class="c"> * @protected</span>
<span class="c"> */</span>
<span class="nx">_defInitFn</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">config</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_instances</span><span class="o">[</span><span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">)]</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_initHierarchy</span><span class="o">(</span><span class="nx">config</span><span class="o">);</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">remove</span><span class="o">(</span><span class="nx">INITIALIZED</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">INITIALIZED</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Default destroy event handler</span>
<span class="c"> *</span>
<span class="c"> * @method _defDestroyFn</span>
<span class="c"> * @protected</span>
<span class="c"> */</span>
<span class="nx">_defDestroyFn</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_destroyHierarchy</span><span class="o">();</span>
<span class="nx">delete</span> <span class="nx">_instances</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">remove</span><span class="o">(</span><span class="nx">DESTROYED</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">DESTROYED</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the top down class hierarchy for this object,</span>
<span class="c"> * with Base being the first class in the array</span>
<span class="c"> *</span>
<span class="c"> * @protected</span>
<span class="c"> * @return {Array} array of classes</span>
<span class="c"> */</span>
<span class="nx">_getClasses</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">_classes</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">constructor</span><span class="o">,</span>
<span class="nx">classes</span> <span class="o">=</span> <span class="o">[];</span>
<span class="k">while</span> <span class="o">(</span><span class="nx">c</span> <span class="o">&amp;&amp;</span> <span class="nx">c</span><span class="o">.</span><span class="nx">prototype</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">classes</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">c</span><span class="o">);</span>
<span class="nx">c</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">superclass</span> <span class="o">?</span> <span class="nx">c</span><span class="o">.</span><span class="nx">superclass</span><span class="o">.</span><span class="nx">constructor</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_classes</span> <span class="o">=</span> <span class="nx">classes</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_classes</span><span class="o">.</span><span class="nx">concat</span><span class="o">();</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Initializes the class hierarchy rooted at this base class,</span>
<span class="c"> * which includes initializing attributes for each class defined </span>
<span class="c"> * in the class&#39;s static ATTRS property and invoking the initializer </span>
<span class="c"> * method on the prototype of each class in the hierarchy.</span>
<span class="c"> * </span>
<span class="c"> * @method _initHierarchy</span>
<span class="c"> * @param {Object} userConf Config hash containing attribute name/value pairs</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_initHierarchy</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">userConf</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">constr</span><span class="o">,</span>
<span class="nx">classes</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getClasses</span><span class="o">();</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">ci</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">cl</span> <span class="o">=</span> <span class="nx">classes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">ci</span> <span class="o">&lt;</span> <span class="nx">cl</span><span class="o">;</span> <span class="nx">ci</span><span class="o">++)</span> <span class="o">{</span>
<span class="nx">constr</span> <span class="o">=</span> <span class="nx">classes</span><span class="o">[</span><span class="nx">ci</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">constr</span><span class="o">.</span><span class="nx">_yuibuild</span> <span class="o">&amp;&amp;</span> <span class="nx">constr</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">constr</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">dynamic</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">ei</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">el</span> <span class="o">=</span> <span class="nx">constr</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">ei</span> <span class="o">&lt;</span> <span class="nx">el</span><span class="o">;</span> <span class="nx">ei</span><span class="o">++)</span> <span class="o">{</span>
<span class="nx">constr</span><span class="o">.</span><span class="nx">_yuibuild</span><span class="o">.</span><span class="nx">exts</span><span class="o">[</span><span class="nx">ei</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_initAtts</span><span class="o">(</span><span class="nx">constr</span><span class="o">.</span><span class="nx">ATTRS</span><span class="o">,</span> <span class="nx">userConf</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">constr</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="nx">INITIALIZER</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">constr</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">INITIALIZER</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Destroys the class hierarchy rooted at this base class by invoking</span>
<span class="c"> * the descructor method on the prototype of each class in the hierarchy.</span>
<span class="c"> *</span>
<span class="c"> * @method _destroyHierarchy</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_destroyHierarchy</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">constr</span><span class="o">,</span>
<span class="nx">classes</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getClasses</span><span class="o">();</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">ci</span> <span class="o">=</span> <span class="nx">classes</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">ci</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">ci</span><span class="o">--)</span> <span class="o">{</span>
<span class="nx">constr</span> <span class="o">=</span> <span class="nx">classes</span><span class="o">[</span><span class="nx">ci</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">constr</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="nx">DESTRUCTOR</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">constr</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">DESTRUCTOR</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Default toString implementation</span>
<span class="c"> * @method toString</span>
<span class="c"> */</span>
<span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">NAME</span> <span class="o">+</span> <span class="s2">&quot;[&quot;</span> <span class="o">+</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">)</span> <span class="o">+</span> <span class="s2">&quot;]&quot;</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Subscribe to a custom event hosted by this object.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s subscribe method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * </span>
<span class="c"> * @method subscribe</span>
<span class="c"> * @param {String} type The type of event to subscribe to. If </span>
<span class="c"> * the type string does not contain a prefix (&quot;prefix:eventType&quot;), </span>
<span class="c"> * the name property of the instance will be used as the default prefix.</span>
<span class="c"> * @param {Function} fn The callback, invoked when the event is fired.</span>
<span class="c"> * @param {Object} context The execution context</span>
<span class="c"> * @param {Object*} args* 1..n params to supply to the callback</span>
<span class="c"> * </span>
<span class="c"> * @return {Event.Handle} unsubscribe handle</span>
<span class="c"> */</span>
<span class="nx">subscribe</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">subscribe</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Fire a custom event by name. The callback functions will be executed</span>
<span class="c"> * from the context specified when the event was created, and with the </span>
<span class="c"> * following parameters.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s fire method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * </span>
<span class="c"> * @method fire</span>
<span class="c"> * @param {String|Object} type The type of the event, or an object that contains</span>
<span class="c"> * a &#39;type&#39; property. If the type does not contain a prefix (&quot;prefix:eventType&quot;),</span>
<span class="c"> * the name property of the instance will be used as the default prefix.</span>
<span class="c"> * @param {Object*} arguments an arbitrary set of parameters to pass to </span>
<span class="c"> * the handler.</span>
<span class="c"> * @return {boolean} the return value from Event.Target.fire</span>
<span class="c"> *</span>
<span class="c"> */</span>
<span class="nx">fire</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]))</span> <span class="o">{</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">type</span><span class="o">){</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">type</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">type</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">fire</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Creates a new custom event of the specified type. If a custom event</span>
<span class="c"> * by that name already exists, it will not be re-created. In either</span>
<span class="c"> * case the custom event is returned. </span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s publish method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> *</span>
<span class="c"> * @method publish</span>
<span class="c"> * @param {String} type The type, or name of the event. If the type does not </span>
<span class="c"> * contain a prefix (&quot;prefix:eventType&quot;), the name property of the instance will </span>
<span class="c"> * be used as the default prefix.</span>
<span class="c"> * @param {Object} opts Optional config params (see Event.Target publish for details)</span>
<span class="c"> * @return {Event.Custom} the custom event</span>
<span class="c"> */</span>
<span class="nx">publish</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">publish</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Subscribe to a custom event hosted by this object. The</span>
<span class="c"> * supplied callback will execute &lt;em&gt;after&lt;/em&gt; any listeners added</span>
<span class="c"> * via the subscribe method, and after the default function,</span>
<span class="c"> * if configured for the event, has executed.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s after method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * @method after</span>
<span class="c"> * @param {String} type The type of event to subscribe to. If </span>
<span class="c"> * the type string does not contain a prefix (&quot;prefix:eventType&quot;), </span>
<span class="c"> * the name property of the instance will be used as the default prefix.</span>
<span class="c"> * @param {Function} fn The callback</span>
<span class="c"> * @param {Object} context The execution context</span>
<span class="c"> * @param {Object*} args* 1..n params to supply to the callback</span>
<span class="c"> */</span>
<span class="nx">after</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">after</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Unsubscribes one or more listeners the from the specified event.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s unsubscribe method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * @method unsubscribe</span>
<span class="c"> * @param type {String|Object} Either the handle to the subscriber or the </span>
<span class="c"> * type of event. If the type</span>
<span class="c"> * is not specified, it will attempt to remove</span>
<span class="c"> * the listener from all hosted events. If </span>
<span class="c"> * the type string does not contain a prefix </span>
<span class="c"> * (&quot;prefix:eventType&quot;), the name property of the </span>
<span class="c"> * instance will be used as the default prefix.</span>
<span class="c"> * @param fn {Function} The subscribed function to unsubscribe, if not</span>
<span class="c"> * supplied, all subscribers will be removed.</span>
<span class="c"> * @param context {Object} The custom object passed to subscribe. This is</span>
<span class="c"> * optional, but if supplied will be used to</span>
<span class="c"> * disambiguate multiple listeners that are the same</span>
<span class="c"> * (e.g., you subscribe many object using a function</span>
<span class="c"> * that lives on the prototype)</span>
<span class="c"> * @return {boolean} true if the subscriber was found and detached.</span>
<span class="c"> */</span>
<span class="nx">unsubscribe</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">context</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]))</span> <span class="o">{</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">unsubscribe</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Removes all listeners from the specified event. If the event type</span>
<span class="c"> * is not specified, all listeners from all hosted custom events will</span>
<span class="c"> * be removed.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Overrides Event.Target&#39;s unsubscribeAll method, to add the name prefix </span>
<span class="c"> * of the instance to the event type, if absent.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * @method unsubscribeAll</span>
<span class="c"> * @param type {String} The type, or name of the event. If </span>
<span class="c"> * the type string does not contain a prefix (&quot;prefix:eventType&quot;), </span>
<span class="c"> * the name property of the instance will be used as the default prefix.</span>
<span class="c"> */</span>
<span class="nx">unsubscribeAll</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">arguments</span><span class="o">;</span>
<span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_prefixEvtType</span><span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">ETP</span><span class="o">.</span><span class="nx">unsubscribeAll</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Utility method to prefix the event name with the</span>
<span class="c"> * name property of the instance, if absent</span>
<span class="c"> *</span>
<span class="c"> * @method _prefixEvtType</span>
<span class="c"> * @private</span>
<span class="c"> * @param {String} type The event name</span>
<span class="c"> */</span>
<span class="nx">_prefixEvtType</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">type</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">SEP</span><span class="o">)</span> <span class="o">===</span> <span class="o">-</span><span class="m">1</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">type</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">&quot;:&quot;</span> <span class="o">+</span> <span class="nx">type</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">type</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">Base</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Attribute</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="m">1</span><span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Base</span> <span class="o">=</span> <span class="nx">Base</span><span class="o">;</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_anim.html">anim</a></li>
<li class=""><a href="module_attribute.html">attribute</a></li>
<li class="selected"><a href="module_base.html">base</a></li>
<li class=""><a href="module_dd.html">dd</a></li>
<li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
<li class=""><a href="module_dump.html">dump</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_oop.html">oop</a></li>
<li class=""><a href="module_queue.html">queue</a></li>
<li class=""><a href="module_substitute.html">substitute</a></li>
<li class=""><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Base.html">Base</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class="selected"><a href="Base.js.html">Base.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>