<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Javacrypt</title>
	<atom:link href="http://javacrypt.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://javacrypt.wordpress.com</link>
	<description>Tales From The JavasCrypt</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:29:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='javacrypt.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/92080149c253c9675ead0101d93a70a1?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Javacrypt</title>
		<link>http://javacrypt.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://javacrypt.wordpress.com/osd.xml" title="Javacrypt" />
	<atom:link rel='hub' href='http://javacrypt.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Thinking About jQuery Pub/Sub with $.Callbacks() and $.Deferred()</title>
		<link>http://javacrypt.wordpress.com/2012/02/18/thinking-about-jquery-pubsub-deferred-w/</link>
		<comments>http://javacrypt.wordpress.com/2012/02/18/thinking-about-jquery-pubsub-deferred-w/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 17:03:00 +0000</pubDate>
		<dc:creator>evolvingtrends</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://javacrypt.wordpress.com/?p=140</guid>
		<description><![CDATA[I&#8217;ll be playing with code and ideas relating to pub/sub pattern based on jQuery $.CallBacks() and $.Deferred() So for now, I just wanted to save the description of the basic usage pattern to come back to it at a later time&#8230; $.Callbacks, $.Deferred and Pub/Sub The general idea behind pub/sub (the Observer pattern) is the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=140&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be playing with code and ideas relating to pub/sub pattern based on jQuery $.CallBacks() and $.Deferred()</p>
<p>So for now, I just wanted to save the description of the basic usage pattern to come back to it at a later time&#8230;</p>
<p>$.Callbacks, $.Deferred and Pub/Sub</p>
<p>The general idea behind pub/sub (the Observer pattern) is the promotion of loose coupling in applications. Rather than single objects calling on the methods of other objects, an object instead subscribes to a specific task or activity of another object and is notified when it occurs. Observers are also called Subscribers and we refer to the object being observed as the Publisher (or the subject). Publishers notify subscribers when events occur</p>
<p>As a demonstration of the component-creation capabilities of $.Callbacks(), it&#8217;s possible to implement a Pub/Sub system using only callback lists. Using $.Callbacks as a topics queue, a system for publishing and subscribing to topics can be implemented as follows:</p>
<p>var topics = {};</p>
<p>jQuery.Topic = function( id ) {<br />
    var callbacks,<br />
        method,<br />
        topic = id &amp;&amp; topics[ id ];<br />
    if ( !topic ) {<br />
        callbacks = jQuery.Callbacks();<br />
        topic = {<br />
            publish: callbacks.fire,<br />
            subscribe: callbacks.add,<br />
            unsubscribe: callbacks.remove<br />
        };<br />
        if ( id ) {<br />
            topics[ id ] = topic;<br />
        }<br />
    }<br />
    return topic;<br />
};</p>
<p>This can then be used by parts of your application to publish and subscribe to events of interest quite easily:</p>
<p>// Subscribers<br />
$.Topic( &#8220;mailArrived&#8221; ).subscribe( fn1 );<br />
$.Topic( &#8220;mailArrived&#8221; ).subscribe( fn2 );<br />
$.Topic( &#8220;mailSent&#8221; ).subscribe( fn1 );</p>
<p>// Publisher<br />
$.Topic( &#8220;mailArrived&#8221; ).publish( &#8220;hello world!&#8221; );<br />
$.Topic( &#8220;mailSent&#8221; ).publish( &#8220;woo! mail!&#8221; );</p>
<p>// Here, &#8220;hello world!&#8221; gets pushed to fn1 and fn2<br />
// when the &#8220;mailArrived&#8221; notification is published<br />
// with &#8220;woo! mail!&#8221; also being pushed to fn1 when<br />
// the &#8220;mailSent&#8221; notification is published. </p>
<p>/*<br />
output:<br />
hello world!<br />
fn2 says: hello world!<br />
woo! mail!<br />
*/</p>
<p>Whilst this is useful, the implementation can be taken further. Using $.Deferreds, it&#8217;s possible to ensure publishers only publish notifications for subscribers once particular tasks have been completed (resolved). See the below code sample for some further comments on how this could be used in practice:</p>
<p>// subscribe to the mailArrived notification<br />
$.Topic( &#8220;mailArrived&#8221; ).subscribe( fn1 );</p>
<p>// create a new instance of Deferreds<br />
var dfd = $.Deferred();</p>
<p>// define a new topic (without directly publishing)<br />
var topic = $.Topic( &#8220;mailArrived&#8221; );</p>
<p>// when the deferred has been resolved, publish a<br />
// notification to subscribers<br />
dfd.done( topic.publish );</p>
<p>// Here the Deferred is being resolved with a message<br />
// that will be passed back to subscribers. It&#8217;s possible to<br />
// easily integrate this into a more complex routine<br />
// (eg. waiting on an ajax call to complete) so that<br />
// messages are only published once the task has actually<br />
// finished.<br />
dfd.resolve( &#8220;its been published!&#8221; );</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javacrypt.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javacrypt.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javacrypt.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=140&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javacrypt.wordpress.com/2012/02/18/thinking-about-jquery-pubsub-deferred-w/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9653602a8ec74789b08adecc0a3fc07?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Katamarius</media:title>
		</media:content>
	</item>
		<item>
		<title>idi.bidi.dom = DOM Anti-Templating Framework</title>
		<link>http://javacrypt.wordpress.com/2011/12/30/javascript-anti-templating/</link>
		<comments>http://javacrypt.wordpress.com/2011/12/30/javascript-anti-templating/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 00:08:53 +0000</pubDate>
		<dc:creator>evolvingtrends</dc:creator>
				<category><![CDATA[anti-templating]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[anti-temlating]]></category>

		<guid isPermaLink="false">http://javacrypt.wordpress.com/?p=82</guid>
		<description><![CDATA[The latest version is a complete revamp that puts this framework ahead of the curve as a light weight, fast and powerful DOM templating framework. project page: http://idibidiart.github.com/idi.bidi.dom/ sources: https://github.com/idibidiart/idi.bidi.dom From the description: project page: http://idibidiart.github.com/idi.bidi.dom/ sources: https://github.com/idibidiart/idi.bidi.dom<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=82&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The latest version is a complete revamp that puts this framework ahead of the curve as a light weight, fast and powerful DOM templating framework.</p>
<p>project page: <a href="http://idibidiart.github.com/idi.bidi.dom/">http://idibidiart.github.com/idi.bidi.dom/</a></p>
<p>sources: <a href="https://github.com/idibidiart/idibididom">https://github.com/idibidiart/idi.bidi.dom</a></p>
<p>From the description:</p>
<p><pre class="brush: plain;">

/*! idi.bidi.dom

 DOM Anti-Templating

 Copyright (c) Marc Fawzi 2012

 http://javacrypt.wordpress.com

 BSD License

 derived from NattyJS v0.08: an open source precursor by the same author

*/

/******************************************************************************
*
* README:
*
* This version works in Gecko and Webkit, not tested on IE
*
* idi.bidi.dom - Javascript Anti-Templating
*
* &quot;All the separation and none of the baggage&quot;
*
* What is it?
*
* Data-Driven DOM &quot;Templating&quot; Without The Templates
*
* How Does It Work?
*
* idi.bidi.dom works by caching the virgin innerHTML (the Node Prototype) of all DOM
* elements (the Nodes) that have a 'idom-node-id' attribute at window.onload
* or $(document).ready. Each Node must contain exactly one direct child at time
* of caching, i.e. the Node Prototype, which must contain special variables (in
* its inner/outer HTML) to be replaced, in a global, dynamic fashion, with JSON
* data (with the scope being the inner/outer HTML of a newly created instance of
* the Node Prototype)
*
* The Node Prototype may hold an arbitrarily complex DOM structure, and one in
* which Node(s) defined elsewhere in the DOM may be dynamically linked by
* reference (called Linked Nodes)
*
* idi.bidi.dom works by creating an instance of the Node Prototype and populating
* the special variables in it with dynamic JSON data (where the JSON keys must
* correspond to the special variables in the Node Prototype) and then inserting
* the newly populated instance into the Node itself, using replace (default on
* first insertion), append or prepend methods, as applied to the Node's entire
* content (the virgin innerHTML or all populated instances of the Node Prototype
* that were previously inserted into the Node) or specific, previously inserted
* instance(s) of the Node Prototype. This basically creates a list of Node
* Prototype instances within the Node (So for convenience, and in the test cases,
* Nodes and Linked Nodes may be referred Node Lists and Linked Node Lists,
* respectively)
*
* idi.bidi.dom allows the DOM to be decomposed into Node Lists each having a
* Node Prototype from which instances (copies, usually with different data) can
* be created, populated with JSON data and then inserted into the Node (in append,
* prepend, and replace modes, with the ability to target specific, previously
* inserted instances of the Node Prototype or the Node List's entire content, i.e.
* the set of instances of the Node Prototype) and where the Node itself can be
* dynamically linked into other Node Lists, which can be linked into other Node
* Lists, and so on...
*
* From an OOP perspective, idom takes the DOM and adds data-bound variables,
* encapsulation, multiple-inheritance and type polymorphism (with the Node
* Prototype as the base for user defined types)
*
* Unlike other template-less DOM rendering frameworks, idom does not take over
* the job of Javascript itself nor does it add any boilerplate, it just gives
* Javascript more power by front-ending the DOM.
*
* Examples:
*
* Take a look at test.html
*
* See Notes under String.prototype._idomMapValues for the expected JSON format
*
* Main Invocation Pattern
*
* .idom$
*
* document.querySelector('#someNode').idom$(data [, options])
*
* behavior: creates new instance of Prototype Node using data to populate the
* special variables in Prototype Node, then append/prepend to (or replace)
* existing instance(s) in the Node
*
* &gt;&gt; data: {key: value, key: value, key: value, etc}
* where the keys must match the idi.bidi.dom node variables in the Node Prototype minus
* the idom$ prefix
*
* &gt;&gt; options: {mode: 'replace'|'append'|'prepend', targetSelector: value,
* ownSelector: value, nodeSelector: value, targetState: value, ownState: value,
* nodeState: value}
*
* if there no populated instances of Prototype Node exist (or if the Node's
* innerHTML was deleted after or before populated instances of Prototype Node
* were inserted) then append/prepend/replace will all replace the Node's
* entire content (if targetSelector is supplied in this case it will throw
* an error, so unless you are sure, you may want to call .$isPopulated() before
* invoking this method with targetSelector or stateSelector options)
*
* targetSelector: optional idom-selector value for instance(s) of Prototpe Node
* to insert the new instance at in append and prepend modes. If null, then
* append/prepend new instance at last/1st instance
*
* targetSelector: optional idom-selector value for instance(s) of Prototpe
* Node to insert into in replace mode. If null, replace entire content of Node
*
* ownSelector: new value of idom-selector value for instance of Prototpe Node
* being inserted
*
* ownState: new value of idom-state attribute for instance of Prototpe Node
* being inserted
*
* targetState: optional idom-selector value for instance of Prototpe Node to in
* sert at in append and prepend modes targetState: optional idom-selector value
* for instance of Prototpe Node to insert at in replace mode
*
* nodeSelector: new value of idom-selector for the Node itself
*
* nodeState: new value of idom-state for the Node itself
*
*
*********************************************************************************
*
* Other available are methods are
*
* .idom$delete([options]) which can delete certain instances of the Node Prototype
* or all instances children (this method is untested as of this release but it
* should work fine, report bugs)
*
* .idom$isPopulated() may be queried before specifying targetSelector or targetState
* to verify existence of populated instance(s) of Node Prototype (the targets)
*
*
*********************************************************************************/
</pre></p>
<p>project page: <a href="http://idibidiart.github.com/idi.bidi.dom/">http://idibidiart.github.com/idi.bidi.dom/</a></p>
<p>sources: <a href="https://github.com/idibidiart/idibididom">https://github.com/idibidiart/idi.bidi.dom</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javacrypt.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javacrypt.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javacrypt.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=82&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javacrypt.wordpress.com/2011/12/30/javascript-anti-templating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9653602a8ec74789b08adecc0a3fc07?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Katamarius</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic Event Handling In Object-Oriented Javascript: A Little Help from JQuery.</title>
		<link>http://javacrypt.wordpress.com/2011/10/17/event-handling-w-object-oriented-javascript-a-little-help-from-jquery/</link>
		<comments>http://javacrypt.wordpress.com/2011/10/17/event-handling-w-object-oriented-javascript-a-little-help-from-jquery/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 22:32:45 +0000</pubDate>
		<dc:creator>evolvingtrends</dc:creator>
				<category><![CDATA[bind]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[Event Handling]]></category>
		<category><![CDATA[hanlder]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[event handling]]></category>

		<guid isPermaLink="false">http://javacrypt.wordpress.com/?p=19</guid>
		<description><![CDATA[Update: jQuery&#8217;s $.proxy (as of 1.7) now implements Function.prototype.bind &#8230; nice Related: Feature Creation and Separation with Object Oriented Javascript Goal: Enable binding/unbinding of event handlers for system and custom events that works in optimal fashion within prototype methods (setup_event and detach_event) as well as within closures. The Technique: About This Technique: Much less overhead than [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=19&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong></p>
<p>jQuery&#8217;s $.proxy (as of 1.7) now implements Function.prototype.bind &#8230; nice</p>
<p><strong>Related:</strong></p>
<p><a href="../2011/10/15/feature-creation-and-separation-with-object-oriented-javascript/">Feature Creation and Separation with Object Oriented Javascript</a></p>
<p><strong>Goal:</strong></p>
<p>Enable binding/unbinding of event handlers for system and custom events that works in optimal fashion within prototype methods (setup_event and detach_event) as well as within closures.</p>
<p><strong>The Technique:</strong></p>
<p><pre class="brush: jscript; html-script: true;">

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
// the constructor

function someObject() {

this.init.apply(this, arguments)

}

// the object prototype

someObject.prototype = {

// this runs every time a new instance is created

init: function(value) {

this.value = value;

},

some_callback: function(arg1, arg2, el) {

return function (event) {

alert (event.type + &quot; on element id = &quot; + el.id  + &quot;, with arguments = &quot; + arg1 + &quot;, &quot; + arg2 + &quot; and an initial value of &quot; + this.value)
}
},

setup_event: function(elem, eventType, handler) {

// important: the inner bind is a re-scoping bind based on Function.prototype.bind not a JQuery bind()

// ns1 is the name space for this object, so events can be removed by eventType AND namespace, giving more flexibility

$(elem).bind(eventType + '.ns1', handler.bind(this))

},

detach_event: function(elem, eventType) {

$(elem).unbind(eventType + '.ns1')

}

}

function demo() {

var obj = new someObject(1);

var el = document.getElementById(&quot;btn&quot;);

// the callback is executed here returning an anonymous function(event) { ... }, allowing the args to the callback (passed at the moment of event setup) and the event itself to be accessed from the returned function

obj.setup_event(el, &quot;click&quot;, obj.some_callback(&quot;Hi&quot;, &quot;There&quot;, el))

setTimeout(function() {

obj.detach_event(el, &quot;click&quot;)

delete obj;

}, 12e3)
}
// ]]&gt;&lt;/script&gt;

&lt;input id=&quot;btn&quot; type=&quot;button&quot; value=&quot;test&quot; /&gt;

&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
// run the demo ... the event handler on the &quot;test&quot; button will work until it's removed after 12 seconds

demo();
// ]]&gt;&lt;/script&gt;

</pre></p>
<p><strong>About This Technique:</strong></p>
<ol>
<li><span style="font-size:medium;">Much less overhead than using JQuery .delegate/undelegate since it uses the bare-bone bind()/unbind() that delegate/undelegate are built on</span></li>
<li><span style="font-size:medium;">JQuery .delegate gets lost inside of JQuery when calling $(element).delegate(<a href="http://element.id/" target="_blank">element.id</a>, eventType + &#8216;.namespaceXYZ&#8217;, handler.bind(this)) from within the &#8220;_setup_event&#8221; prototype method, with the result being the error: &#8220;handler&#8221; not defined. If .bind(this) is not present, JQuery presumably attaches the handler but since the handler code references &#8220;this&#8221; for the object instance (and &#8220;this&#8221; without .bind(this) refers to the element) it doesn&#8217;t know what to do and no error is reported in Firebug (that&#8217;s one place where JQuery should throw an exception, and I think I might complain to them about it.)</span></li>
<li><span style="font-size:medium;">It allows the &#8220;this&#8221; keyword (of the object instance), the event itself and any variables from the outer function (that is enclosing the setup_event method) to be transferred to the handler at the time _setup_event is called, so it works normally in loops referencing outer function variables.</span></li>
</ol>
<p><strong><span style="font-size:medium;">In other words, the technique is ideal for use within closures and prototype methods.</span></strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javacrypt.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javacrypt.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javacrypt.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=19&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javacrypt.wordpress.com/2011/10/17/event-handling-w-object-oriented-javascript-a-little-help-from-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9653602a8ec74789b08adecc0a3fc07?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Katamarius</media:title>
		</media:content>
	</item>
		<item>
		<title>Feature Creation and Separation with Object Oriented Javascript (for Exclusively Client Side Apps)</title>
		<link>http://javacrypt.wordpress.com/2011/10/15/feature-creation-and-separation-with-object-oriented-javascript/</link>
		<comments>http://javacrypt.wordpress.com/2011/10/15/feature-creation-and-separation-with-object-oriented-javascript/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 00:13:17 +0000</pubDate>
		<dc:creator>evolvingtrends</dc:creator>
				<category><![CDATA[Anonymous Functions]]></category>
		<category><![CDATA[Feature Separation]]></category>
		<category><![CDATA[Object Oriented Javascript]]></category>
		<category><![CDATA[Separation of Concerns]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Aspect Oriented Programming]]></category>
		<category><![CDATA[Prototypal Inheritance]]></category>

		<guid isPermaLink="false">http://javacrypt.wordpress.com/?p=9</guid>
		<description><![CDATA[Feb 22, 2012 Udpate: I&#8217;m embracing the Backbone.js client-side MVC model, including Backbone.Controller pattern. in conjunction with the self-authored anti-templating framework idom for server-driven Javascript apps (Backbone in its current state needs major modifications to work for exclusively client-side apps) The feature-oriented encapsulation pattern below is for exclusively client side apps and can be extended [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=9&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Feb 22, 2012 Udpate</strong>:</p>
<p><strong>I&#8217;m embracing the Backbone.js client-side MVC model, including Backbone.Controller pattern. in conjunction with the self-authored anti-templating framework <a href="http://javacrypt.wordpress.com/2011/12/30/javascript-anti-templating/">idom</a></strong> <strong>for server-driven</strong><strong> Javascript apps (Backbone in its current state needs major modifications to work for exclusively client-side apps)<br />
</strong></p>
<p><strong>The feature-oriented encapsulation pattern below is for exclusively client side apps and can be extended with <a href="http://javacrypt.wordpress.com/2012/02/18/thinking-about-jquery-pubsub-deferred-w/">jQuery $.Callbacks()/$.Deferred() based pub-sub</a> bus to connect the feature objects together. Any DOM rendering objects used here can be replaced with or upgraded to use <a href="http://javacrypt.wordpress.com/2011/12/30/javascript-anti-templating/">idom</a>.</strong></p>
<p><strong>Version: 0.5</strong></p>
<p><strong>Updated:</strong> Nov 4, 2011</p>
<p><strong>Required familiarity:</strong></p>
<p>Aspect Oriented Programming, Separation of Concerns, Object Oriented Javascript, Prototypal Inheritance, Anonymous Functions</p>
<p><strong>The question:</strong></p>
<p>How do you create and separate features in JS using Object Oriented Programming (OOP) techniques?</p>
<p>The requirement is that each Feature is encapsulated within an anonymous function scope and all that&#8217;s exposed is an object literal with public methods, including methods for getting/setting properties.</p>
<p>Also, objects must operate exclusively in the window they&#8217;re defined in, so you don&#8217;t end up with features being defined across many windows.</p>
<p>This model also assumes:</p>
<p>1) window._globals object literal defined in the main app window that contains global variables that can be accessed by all features in the same window (using window._globals.someVar) as well as features within iframes (using partent.window._globals.someVar). Applications with completely separate windows would simply implement this model separately per each window, including iframes in each window.</p>
<p>2) presentation logic as well as business/computational logic is decomposed into distinct Features  and implemented using multi-instance objects (which may use dynamic event binding/unbinding in case of DOM/SVG elements) that provide an OO interface to the DOM/SVG elements and the Canvas within the given Feature and only expose methods to the outside on the returned object literal, including the methods for get/set properties.</p>
<p>3) coordination logic that is not part of any distinct Feature is not part of the model</p>
<p><strong>Overall Goal:</strong></p>
<p>To show that it is possible to construct features in a way that allows developers to maintain them as separate modules without having to resort to much more fancy frameworks/client-side-middleware that don&#8217;t work as well for feature separation and performance.</p>
<p><strong>Here is the basic homegrown AOP method for OO Javascript:</strong></p>
<p><pre class="brush: jscript;">

window.someFeature = (function(){

/*

The properties variable below is an object literal used for storing properties and their values that are available to actual objects within this anonymous function. See the bottom of this anonymous function for the returned object literal, which exposes public methods (accessed as window.someFeature.publicMethodName), including setProperties and getProperties.

*/

var properties = {}

properties.property1 = 0;
properties.property2 = &quot;some initial value&quot;;

...

properties.propertyN = window._globals.someVar;  // or parent.window._globas.someVar if this window happens to be an ifarme

/*

a basic private object that implements some computation or business logic. It can be referenced anywhere within the self executing anonymous function, including in the private objects and publicly exposed methods.

*/

var somePrivateObject = function () {

this.initialize.apply(this, arguments);

}

somePrivateObject.prototype = {

initialize: function(args){

// initialized upon instantiation
// initialize code goes here

},

someMethod: function(args) {

// do something
// return something

},

...

anotherMethod: function(args) {

// do something
// return something

}

}

/*

a private object that operates on a DOM element (as container). It can be referenced anywhere within the self executing anonymous function, including in the private objects and publicly exposed methods.

*/

var somePrivateDOMObject = function () {

this.initialize.apply(this, arguments);

}

somePrivateDOMObject.prototype = {

initialize: function(someDiv){

// this is the constructor method (implemented on the prototype) that populates someDiv container with some child elements and attaches event handlers to them
// setup_event would be a prototype method on this object and is covered in the article linked at the bottom of this page

},

destroy: function(someDiv){

// not sure if all browsers garbage-collect event handlers immediately when elements are removed so, just in case,
// call detach_event to detach event handlers assigned by this object
// detach_event would be a prototype method on this object and is covered in the article linked at the bottom of this page
// then find out if element supports innerHTML and if so nullify content. Else, adjust strategy as necessary
},

someMethod: function(args) {

// do something
// return something

}

}

/*

some private clone-able object that operates on DOM and/or implements some computation or business logic and can be referenced anywhere within the self executing anonymous function, including in the private objects and publicly exposed methods.

Actual implementation would be for DOM or no DOM (no need to combine both modes into one object)

*/

var somePrivateCloneableObject = function () {

this.initialize.apply(this, arguments);

}

somePrivateCloneableObject.prototype = {

initialize: function(){

// this is the constructor method (implemented on the prototype) for a clone-able object where
// arguments[0] ... arguments[n] contain state data or arguments[0] contains the parent
// DOM element from which state data can be copied, e.g. innerHTML, style, etc
// Actual implementation would be for DOM or no DOM (no need to combine both modes into one object)

},

// here is some method

someMethod: function(args){

// do something

// update state data (if not using DOM element as argument for cloning)

// return something

},

...

// here is a method for cloning the given instance

clone: function(){

// copy the state data of the existing instance of somePrivateCloneableObject (i.e. this.var1 ... this.var4)
// or get the actual DOM element somePrivateCloneableObject operates on
// and pass it to the constructor for this clone-able object
// Actual implementation would be for DOM or no DOM (no need to combine both modes into one object)

var objInstance = new somePrivateCloneableObject(args);

// return the cloned instance

return objInstance;

},

destroy: function(domCleanup){

// called with (true) if object operates on DOM element and not implementing just computation/business logic
// Actual implementation would be for DOM or no DOM (no need to combine both modes into one object)

if (domCleanup) {

// not sure if all browsers automatically remove event handlers immediately when elements are removed so, just in case,
// call detach_event to detach event handlers assigned by this object
// detach_event would be a prototype method on this object and is covered in the article linked at the bottom of this page
// then nullify the element's innerHTML to clean the DOM.

}

},

// initialize object state data

 var1:0,
 var2:&quot;something&quot;,
 var3:100,
 var4:{}

...

}

// methods exposed publicly thru the returned object literal

var someExposedMethod1 = function(args) {

// this method may create new instances of the previously defined private objects (which can access the properties object) and call methods on each of them

};

var someExposedMethod2 = function(args) {

// this method may create new instances of the previously defined private objects (which can access the properties object) and call methods on each of them

};

// properties set/get methods accessible thru returned object

var set = function(propObject){

if (!propObject) return null;

// sets properties per the object literal propObject, accessed as window.someFeature.setProperties({propert1: value1, ... , propertyN: valueN} Assigns existing values for properties missing from propObject

properties.property1 = propObject.property1 || properties.property1;

properties.property2 = propObject.property2 || properties.property2;

properties.propertyN = propObject.propertyN || properties.propertyN;

}

var get = function(){

if (!arguments) return null;

// gets properties, accessed as window.someFeature.getProperties(&quot;property1&quot;, ..., &quot;propertyN&quot;) which return the object literal containing properties and their values

var propObj = {};

for (n = 0; n &lt; arguments.length; n++) {

// returns undefined if property doesn't exist or null if any of property names is not a string

 if (typeof arguments[n] != 'string') return null;

 propObj[arguments[n]] = properties[arguments[n]];

}

return propObj;

}

return propObj;

}

// the returned object exposes public methods including set/get properties

return {

&quot;somePublicMethod1&quot;: someExposedMethod1,

&quot;somePublicMethod2&quot;: someExposedMethod2,

&quot;setProperties&quot;:set,

&quot;getProperties&quot;:get
};

}());

</pre></p>
<p>Also Relevant:</p>
<p><a href="../2011/10/17/event-handling-w-object-oriented-javascript-a-little-help-from-jquery/" rel="next">Dynamic Event Handling In Object-Oriented Javascript: A Little Help From JQuery </a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javacrypt.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javacrypt.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javacrypt.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=9&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javacrypt.wordpress.com/2011/10/15/feature-creation-and-separation-with-object-oriented-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9653602a8ec74789b08adecc0a3fc07?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Katamarius</media:title>
		</media:content>
	</item>
		<item>
		<title>About my Javascript+HTML5+Canvas+SVG project</title>
		<link>http://javacrypt.wordpress.com/2011/10/14/about-my-javascript-html5-svg-project/</link>
		<comments>http://javacrypt.wordpress.com/2011/10/14/about-my-javascript-html5-svg-project/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 18:08:12 +0000</pubDate>
		<dc:creator>evolvingtrends</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://javacrypt.wordpress.com/?p=7</guid>
		<description><![CDATA[One day I decided to try out Twitter (about 9 months ago) &#8230; I was browsing people’s feeds and adding folks and somehow I ended up with a tweet on my timeline that was made entirely of unicode characters, the kind that was used in terminals to display user interface elements before bitmapped graphics came [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=7&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One day I decided to try out Twitter (about 9 months ago) &#8230;</p>
<p>I was browsing people’s feeds and adding folks and somehow I ended up with a tweet on my timeline that was made entirely of unicode characters, the kind that was used in terminals to display user interface elements before bitmapped graphics came along.</p>
<p>It inspired me to make an Editor for this kind of art (which is called “Twitter Art” by the way)</p>
<p>Make sure to watch these demonstration videos videos on youtube in HD (720p)</p>
<p><a href="http://www.youtube.com/watch?v=Wd-d1p-c56U">http://www.youtube.com/watch?v=Wd-d1p-c56U</a> (Original)</p>
<p><a title="twitter art save, print, color, morph" href="http://www.youtube.com/watch?v=UX5jOvdLG8c" target="_blank">http://www.youtube.com/watch?v=UX5jOvdLG8c</a> (Canvas2Vector Effects 1)</p>
<p><a href="http://www.youtube.com/watch?v=jCAp22_HYLk%20" target="_blank">http://www.youtube.com/watch?v=jCAp22_HYLk </a>(Canvas2Vector Effects 2)</p>
<p><a href="http://www.youtube.com/watch?v=R1fin3jBFTw" target="_blank">http://www.youtube.com/watch?v=R1fin3jBFTw</a> (Canvas2Vector Effects 3)</p>
<p><a href="http://www.youtube.com/watch?v=VLyLb3Otw5s" target="_blank">http://www.youtube.com/watch?v=VLyLb3Otw5s</a> (SVG Saving And Manipulation)</p>
<p>Some features and aspects are patent pending, and I’m working on free open source license for non-commercial use and also a royalty-free commercial license with commented sources, to help this new medium take hold, etc.</p>
<p>The app is built entirely with Javacsript, HTML5 (canvas), and SVG. There are no server components, other than a 20-line Python HTTP server based on Google Appengine API. Static HTML5, JS and .png files are served to the client and everything runs inside the browser.</p>
<p><a title="idi.bidi.art Twitter Art Editor :)" href="http://idibidiart.com/" target="_blank">http://idibidiart.com</a></p>
<p>It  runs only on Firefox, the People’s Browser, not your faster-than-potato Chrome or whatever, and actually it is because of the non-groovy way Chrome and IE handle unicode line breaking that made me delay the cross-browser implementation. A lot of it is black magic (or more exactly: an ancient line-breaking algorithm that no one has looked at in ages)</p>
<p>Enjoy and be challenged.</p>
<p>@idibidiart</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javacrypt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javacrypt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javacrypt.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javacrypt.wordpress.com&amp;blog=28442509&amp;post=7&amp;subd=javacrypt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javacrypt.wordpress.com/2011/10/14/about-my-javascript-html5-svg-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9653602a8ec74789b08adecc0a3fc07?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Katamarius</media:title>
		</media:content>
	</item>
	</channel>
</rss>
