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

<channel>
	<title>I should remember this</title>
	<atom:link href="http://gledovic.com/feed" rel="self" type="application/rss+xml" />
	<link>http://gledovic.com</link>
	<description>One&#039;s read, test and research logs.</description>
	<lastBuildDate>Wed, 15 Feb 2012 08:55:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQuery solution for form submitting on enter &#8211; the event capturing/bubbling problem</title>
		<link>http://gledovic.com/form-is-not-submitting-on-enter-the-event-capturing-bubbling-problem-jquery-solution</link>
		<comments>http://gledovic.com/form-is-not-submitting-on-enter-the-event-capturing-bubbling-problem-jquery-solution#comments</comments>
		<pubDate>Fri, 27 May 2011 20:33:37 +0000</pubDate>
		<dc:creator>Dusan Gledovic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://gledovic.com/blog/?p=226</guid>
		<description><![CDATA[Problem with form not submitting when Enter is pressed has its background in implementation of event bubbling and/or event capturing. In Internet Explorer events bubbles, on the other hand in other browsers events are being captured and bubbled. Yay! You can read further on that matter in article on event order at quirksmode.org, which is [...]]]></description>
			<content:encoded><![CDATA[<p>Problem with form not submitting when Enter is pressed has its background in implementation of event bubbling and/or event capturing. In Internet Explorer events bubbles, on the other hand in other browsers events are being captured and bubbled. Yay!</p>
<p><span id="more-226"></span>You can read further on that matter in <a title="Event bubbling and capturing problem explained" href="http://www.quirksmode.org/js/events_order.html" target="_blank">article on event order</a> at <a title="QuirksMode - for all your browser quirks" href="http://www.quirksmode.org/" target="_blank">quirksmode.org</a>, which is great site and you should certainly spend some time over there if you already haven&#8217;t.</p>
<p>Let&#8217;s get down to the essence of this article, which is handling problem of form not submitting when Enter is pressed while some text input field has focus and solution you could find in jQuery.</p>
<p>You have and form:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form id=&quot;signup&quot; action=&quot;/process/login-form&quot; method=&quot;post&quot;&gt;
  &lt;label for=&quot;answer1&quot;&gt;What are you think about blue?&lt;/label&gt;
  &lt;input id=&quot;answer1&quot; name=&quot;answer1&quot; type=&quot;text&quot; /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Answer&quot; /&gt;
&lt;/form&gt;
</pre>
<p>and it is bugged down (I have no idea if this phrase exists) as explained above, you are using jQuery (please, don&#8217;t use jQuery just to overcome this obstacle &#8211; it is non sense) and you are thinking about your solutions.</p>
<p>One of the solutions could be:</p>
<pre class="brush: jscript; title: ; notranslate">
	$(&quot;#answer1&quot;).keydown(function(event){
		if(event.keyCode == 13 &amp;&amp; jQuery.support.submitBubbles) {
			$(this).parents(&quot;form&quot;).submit();
		};
	})
</pre>
<p>What that code does is it binds keypress event to the input field of interest and checks on keypress (when that field has focus) if event code corresponds to the keyCode (13) of the Enter key and if it does it sends submit to the parent form, which could be called by its id, but this way you can address different input fields with same class from different forms, which is not rare on web today, to have a whole bunch of forms in one page.</p>
<p><a title="jQuery.support page in jQuery reference" href="http://api.jquery.com/jQuery.support/" target="_blank">jQuery.support object</a> is &#8220;A collection of properties that represent the presence of different browser features or bugs.&#8221; as it is said in <a title="Link to jQuery reference web site" href="http://api.jquery.com/" target="_blank">jQuery reference</a>. It relies on feature detection (not browser detection) which is recommended and  safer method.</p>
<p>I hope you find this article helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://gledovic.com/form-is-not-submitting-on-enter-the-event-capturing-bubbling-problem-jquery-solution/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big and Little Endian Explained</title>
		<link>http://gledovic.com/big-and-little-endian-explained</link>
		<comments>http://gledovic.com/big-and-little-endian-explained#comments</comments>
		<pubDate>Fri, 04 Mar 2011 01:29:17 +0000</pubDate>
		<dc:creator>Dusan Gledovic</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://gledovic.com/blog/?p=213</guid>
		<description><![CDATA[I was looking for resource to refresh my memory on story of endians and stumbled upon this great post: Understanding big and little endian byte order I am really impressed how some people know to deliver such a great contribution to cyberspace. Bravo and thank you to the author Kalid Azad.]]></description>
			<content:encoded><![CDATA[<p>I was looking for resource to refresh my memory on story of endians and stumbled upon this great post:</p>
<p><a title="Understanding big and little endian byte order" href="http://betterexplained.com/articles/understanding-big-and-little-endian-byte-order/" target="_blank">Understanding big and little endian byte order</a></p>
<p>I am really impressed how some people know to deliver such a great contribution to cyberspace.</p>
<p>Bravo and thank you to the author Kalid Azad.</p>
]]></content:encoded>
			<wfw:commentRss>http://gledovic.com/big-and-little-endian-explained/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Singleton Design Pattern Demystified</title>
		<link>http://gledovic.com/javascript-singleton-design-pattern-demystified</link>
		<comments>http://gledovic.com/javascript-singleton-design-pattern-demystified#comments</comments>
		<pubDate>Mon, 07 Feb 2011 18:29:11 +0000</pubDate>
		<dc:creator>Dusan Gledovic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Object Oriented JavaScript]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[javascript design patterns]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[object oriented javascript]]></category>

		<guid isPermaLink="false">http://gledovic.com/blog/?p=149</guid>
		<description><![CDATA[Singleton is one of the creational design patterns. It serve purpose of &#8220;restricting the instantiation of a class to one object&#8221;. (wikipedia) Because of its nature, JavaScript has different way of implementation of the Singleton Pattern than &#8220;traditional&#8221; object-oriented languages like Java, C#, PHP etc. To get proper Singleton implementation (in JavaScript) we have to [...]]]></description>
			<content:encoded><![CDATA[<p>Singleton is one of the <strong>creational design patterns</strong>. It serve purpose of &#8220;restricting the instantiation of a class to one object&#8221;. <sup><a href="http://en.wikipedia.org/wiki/Singleton_pattern">(wikipedia)</a></sup></p>
<p>Because of its nature, JavaScript has different way of implementation of the Singleton Pattern than &#8220;traditional&#8221; object-oriented languages like Java, C#, PHP etc.</p>
<p><span id="more-149"></span></p>
<p>To get proper Singleton implementation (in JavaScript) we have to fulfill following demands:</p>
<ul class="real_ul_list">
<li>once instantiated, attempt to instantiate same class again should actually return the first object</li>
<li>instance should not be rewritable</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
function Test() {
	// private
	var instance = this;

	// rest of the code

	// overwriting itself (constructor) from global space
	// so that following calls to new Test();
	// actually returns private variable instance
	Test = function () {
		return instance;
	};
}

obj1 = new Test();
obj2 = new Test();

obj1 === obj2 // result: true
</pre>
<p>This pattern uses power of closures to preserve global namespace from cluttering and instance from being overridden from that same space, the global one.</p>
<p>In above primer we have Test class. In it there is instantiated variable instance with var keyword so that it becomes private variable. Then <a href="http://en.wikipedia.org/wiki/This_%28computer_science%29">this</a> is assigned to it so that it could be called from inner functions and most of all inner Test function which will override its parent Test (because of the same name) constructor from global namespace once the parent gets instantiated.</p>
<p>That&#8217;s the reason obj1 and obj2 identity comparison returns true, because second call new Test() actually just returns instance variable. Keeping in mind that objects are passed by reference in JavaScript, it&#8217;s obvious that obj1 and obj2 are just different name pointing to the same address in memory.</p>
<pre class="brush: jscript; title: ; notranslate">
function Test() {
	// private
	var instance = this;

	// rest of the code
	// ...

	// private
	var oneVeryImportanFunction = function(){
		alert(typeof instance);
	}

	// public
	this.getType = function(){
            oneVeryImportanFunction();
	}

	// overwriting itself (constructor) from global space
	// so that following calls to new Test();
	// actually return private variable instance
	Test = function () {
		return instance;
	};
}

obj1 = new Test();
obj2 = new Test();

obj1 === obj2;

obj2.getType();
</pre>
<p>Usually, &#8220;By convention, we make a private that&#8221; = this &#8221; variable. This is used to make the object available to the private methods. This is a workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functions.&#8221; <sup><a href="http://javascript.crockford.com/private.html">crockford</a></sup> , but here in oneVeryImportanFunction() function we could use instance variable as it serves same thing like that, but it has different name.</p>
]]></content:encoded>
			<wfw:commentRss>http://gledovic.com/javascript-singleton-design-pattern-demystified/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Classical constructor function in JavaScript class</title>
		<link>http://gledovic.com/classical-constructor-function-in-javascript-class</link>
		<comments>http://gledovic.com/classical-constructor-function-in-javascript-class#comments</comments>
		<pubDate>Sat, 29 Jan 2011 01:32:12 +0000</pubDate>
		<dc:creator>Dusan Gledovic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Object Oriented JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript constructor function]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[object oriented javascript]]></category>

		<guid isPermaLink="false">http://gledovic.com/blog/?p=43</guid>
		<description><![CDATA[I was in search (~5 min) for classical constructor for classes in JavaScript. What I found is nothing. It lasted too short, I guess, but anyway I did some tests and I got to the solution that could easily act as JavaScript class constructor. The complete Test class: And html: Output is of course: Dusan [...]]]></description>
			<content:encoded><![CDATA[<p>I was in search (~5 min) for classical constructor for classes in JavaScript. What I found is nothing. It lasted too short, I guess, but anyway I did some tests and I got to the solution that could easily act as JavaScript class constructor.</p>
<p><span id="more-43"></span></p>
<p>The complete Test class:</p>
<pre class="brush: jscript; title: ; notranslate">function Test(name){

	var that = this;

	var fname;

	var __construct = function(passedName){
		fname = passedName;
	}(name);

	this.getName = function(){
		return fname;
	};

	this.changeText = function(){
		document.getElementById(&quot;name&quot;).innerHTML = this.getName();
	}
}

var Test = new Test(&quot;Dusan&quot;);
Test.changeText();</pre>
<p>And html:</p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;
	&lt;head&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;name&quot;&gt;&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Output is of course: Dusan</p>
<p>Whole point is within few lines of code:</p>
<pre class="brush: jscript; title: ; notranslate">var __construct = function(passedName){
	fname = passedName;
}(name);</pre>
<p>__construct is private self invoking function and it is passed name param during Test object construct. It sets fname var to name param value.</p>
<p>It could easily be something more complex like config object:</p>
<pre class="brush: jscript; title: ; notranslate">function Test(configObject){
	var __construct = function(params){
		fname = params[&quot;fname&quot;];
		lname= params[&quot;lname&quot;];
	}(configObject);</pre>
<p>This is anything, but a complex, but you got an idea.</p>
<h3>Notes:</h3>
<ul>
<li>You can name __construct function as you wish. I named it like this for clarity and because of my PHP roots. <img src='http://gledovic.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>__construct returns void so there is no possibility of revoking it. It becomes typeof &#8220;undefined&#8221;.</li>
<li>It has to be defined like <span style="background-color: ##f9f9f9;"> var chooseContructorName = function(){&#8230;} </span> to stay private and to parse as self invoking.</li>
</ul>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://gledovic.com/classical-constructor-function-in-javascript-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World</title>
		<link>http://gledovic.com/hello-world</link>
		<comments>http://gledovic.com/hello-world#comments</comments>
		<pubDate>Sat, 15 Jan 2011 02:23:55 +0000</pubDate>
		<dc:creator>Dusan Gledovic</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://gledovic.com/blog/?p=9</guid>
		<description><![CDATA[After ages of &#8220;having more important stuff at the moment&#8221;, I finally did it, in 5 minutes as WordPress crew brags about, I set up the blog on my site, instead of my old site from freelancing era. I am looking forward to logging my thoughts on web development, programming etc. It&#8217;ll be fun.]]></description>
			<content:encoded><![CDATA[<p>After ages of &#8220;having more important stuff at the moment&#8221;, I finally did it, in 5 minutes as WordPress crew brags about, I set up the blog on my site, instead of my old site from freelancing era.</p>
<p>I am looking forward to logging my thoughts on web development, programming etc.</p>
<p>It&#8217;ll be fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://gledovic.com/hello-world/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

