<?xml version="1.0" encoding="UTF-8"?>	<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
		<channel>
		
			<title>
				Radoslav Popov RSS
			</title>
			<link>http://radoslavpopov.com/</link>
			<language>en-us</language>
			<description>
				Radoslav Popov RSS
			</description>
			
							<item>
					<title>Me on Microsoft Days</title>
					<description><![CDATA[ <p>I didn't believe that I would've ever said that, but I've just attended the <a href="http://www.msbgregistration.com/">Microsoft Days 2012</a> here in Sofia. Being too far away from any Microsoft technology, it was really a nice pleasure to get first-hand information about what is going on in the IT industry today. Some random thoughts that are important to me:</p>
<ul>
<li><strong>Cloud has become a key strategy <span class='keyword'>for</span> Microsoft</strong> - It was quite annoying that more than half of all lectures were somehow related to cloud and virtualization. I expected more web-related stuff, but somehow <span class='keyword'>this</span> topic, as well as the birth of Windows 8, have overtaken the event.</li>
<li><strong>Google App Engine, Amazon Web Services, Microsoft Azure</strong> - These are the biggest competitor to rule the cloud world. Google is ahead of all by providing free services that may very well be sufficient even <span class='keyword'>for</span> small businesses.</li>
<li><strong>Metro design style is something big</strong> - The difference between Windows 7 and 8 is way bigger than the one between 95 and 7. Huge interface shift!</li>
<li><strong>.Net MVC is something everyone use</strong> - The world has realised that the more control you have on the HTML, CSS and JavaScript, the better. The days of JSF-like frameworks are finally over. For good!</li>
<li><strong>Still, there is a really smart guy in <span class='keyword'>this</span> world that uses a single language to build a full-stack web applications and <span class='keyword'>this</span> language is not JavaScript</strong> - <a href="http://www.intellifactory.com/blogs/adam.granicz/">Adam Granicz</a> uses F# <span class='keyword'>for</span> the server-side logic and somehow to generate the JavaScript. And he also states that <span class='keyword'>this</span> approach leads to faster development, reduces the amount of code and simplifies maintenance. I can understand the reducing of code because F# is a <span class='keyword'>function</span>al language and we all know how powerful the <span class='keyword'>function</span>al programming paradigm is, but come on ... something to generate your JavaScript! Blah!</li>
<li><strong>jQuery Mobile unobtrusively boost your mobile web application usability</strong> - Just add it to your page.</li>
<li><strong>Knockout.js is gaining momentum</strong> - two completely different lectures demonstrated applications built with knockout. This fact speaks <span class='keyword'>for</span> itself.</li>
<li><strong>log4javascript is a great choice <span class='keyword'>for</span> logging in JavaScript</strong></li>
<li><a href="http://gyorgybalassy.wordpress.com/">György Balássy</a> is a cool guy and wonderful lecturer :)</li></ul>
<p>To be honest, I can't wait <span class='keyword'>for</span> the next year event. But please, provide more web oriented lectures!</p> ]]></description>
					<pubDate>Thu, 29 Mar 2012 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/general/me-on-microsoft-days</guid>
					<link>http://radoslavpopov.com/general/me-on-microsoft-days</link>
					<category>general</category>
				</item>
							<item>
					<title>Explaining Web to Hard Programmers</title>
					<description><![CDATA[ <p>I will use the term <strong>hard programmers</strong> here to describe people with background in server-side development and compiled languages like C++ and Java, who have never been involved in real web development. I first stumbled across <span class='keyword'>this</span> term when I was reading the book <a href="http://www.quirksmode.org/book/">ppk on JavaScript</a>. </p>
<p>Being surrounded by hard programmers myself, I found that describing all the specifics, processes and tendencies of web development to them is a challenging task. <strong>There are fundamental differences how traditional and web applications work.</strong> If you do not believe me, look at two questions that looks akward <span class='keyword'>for</span> web professionals, but are commonly asked by hard programmers:</p>
<ul>
<li>When will HTML5 be ready?</li>
<li>Is it possible to use HTML5 and CSS3 when the browsers do not support it?</li></ul>
<p>There are many variants of these questions, but basically, all of them regard the <strong>lack of features in browsers</strong>, something that web professionals know how to overcome. Hard programmers, however, do not face such a problem in other environments, where something either is working and can be used, or is not working and cannot be used at all.</p>
<p>So here are several points you should mention in front of hard programmers to explain how the Web works:</p>
<h2> HTML5 and CSS3 are modular - each module has a separate life</h2>
<p>What modular means in <span class='keyword'>this</span> case is that there are separate specifications <span class='keyword'>for</span> the different features and each of them is in different state (draft, recommendation, etc). Same goes <span class='keyword'>for</span> the implementations. While one feature may be very popular in mass media and thus implemented well even in early draft (<a href="http://www.w3.org/TR/css3-2d-transforms/">2D Transformation</a> being a good example), other may lack support in any browser today. </p>
<p>Having in mind the big competition between the browser vendors, waiting <span class='keyword'>for</span> all the specifications to become recommendations is not possible. Moreover,  no one knows what &quot;all the specifications&quot; means. A <span class='keyword'>new</span> draft, <span class='keyword'>for</span> example, may be released tomorrow. This is an ongoing process. New features are continuously proposed. Not believing again? Look at <a href="http://dev.w3.org/csswg/selectors4/">css4 selectors</a>, <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">Fullscreen API</a>, or the proposition about <a href="http://lists.w3.org/Archives/Public/www-dom/2011OctDec/0020.html">simplifying element creation</a>. </p>
<p>This environment differs from Java SE, <span class='keyword'>for</span> example. When JDK 7 is released, you have all the features ready to be used. No partial implementations, no hacks to triggers a feature, no vendor prefixes. </p>
<h2> Web apps do not need to behave the same in each platform</h2>
<p>If <a href="http://dowebsitesneedtolookexactlythesameineverybrowser.com/"><span class='keyword'>this</span></a> or <a href="http://dowebsitesneedtobeexperiencedexactlythesameineverybrowser.com/"><span class='keyword'>this</span></a> are not enough <span class='keyword'>for</span> you, here are some additional arguments in a form of examples:</p>
<ul>
<li>The Google Docs application has an offline mode. Does it work in old browsers? No. Does Google care? No. The core <span class='keyword'>function</span>ality - to work online with documents, is always there. The offline mode is an <strong>enhancement</strong> <span class='keyword'>for</span> users that use modern browsers.</li>
<li>Twitter home page uses many CSS3 effects (shadows, rounded corners, opacity). Do these effects work in old browsers? No. Does Twitter care? No. The core <span class='keyword'>function</span>ality - to identify the brand and to log-in/register is always there. CSS3 is only an <strong>enhancement</strong> <span class='keyword'>for</span> users that use modern browsers.</li></ul>
<p>Building applications with basic technologies while enhancing with features <span class='keyword'>for</span> advanced browsers is a tendency in web development which will never vanish. Hard programmers get to <span class='keyword'>this</span> paradigm very slow because there is no analogy with traditional application development, where everything should work the same in each platform. </p>
<p>Paul Boag has made a <a href="http://boagworld.com/design/where-are-my-rounded-corners/">great document on how to explain the need of progressive enhancement to our clients</a>. This might very well work <span class='keyword'>for</span> hard programmers too.</p>
<h2> JavaScript is dynamic - it can implement features that lack support</h2>
<p>An example that I really like because it shows the conceptional differences between JavaScript and other languages hard programmers are used to, is the following: in Java, you cannot use generics <span class='keyword'>if</span> you want to compile in Java 4. And you cannot define it. In JavaScript, you can implement generics in a browser that do not support it and still use it. </p>
<p>For a real example, <a href="http://dev.w3.org/html5/webstorage/">localStorage</a> can be implemented on top of other storage mechanisms that is available in the browser (IE userData, Flash Shared Object, Cookies...). And you will still use the localStorage API as <span class='keyword'>if</span> it is available in the browser. </p>
<p>For a concrete application, see <a href="http://www.diagram.ly/">diagram.ly</a>, which relies on <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics">SVG</a>, but also works in IE7.</p>
<h2> HTML and CSS are not programming languages, but it helps to treat them as <span class='keyword'>if</span> they are</h2>
<p>Although hard programmers are aware of the best practices to write source code, my observations on their markup and front-end code are discouraging. They copy-paste a lot of HTML, CSS and JavaScript handlers written directly in the markup and they don't have any clue that <span class='keyword'>this</span> code should also be organized or that some principles should be followed. </p>
<p>If you are a web professional who has to work with hard programmers, explain to them that HTML and CSS are also source code and make them think about these technologies as programming languages. That may help to trigger some sense to follow best practices. </p>
<h2> Final Note</h2>
<p>I recently helped my colleague <a href="http://twitter.com/#!/pltod">Plamen Todorov</a> to create <span class='keyword'>this</span> excellent <a href="https://docs.google.com/presentation/d/1rszjtX-dNj1NSP-fpRJ96fArmZFJ1eE7Xi49dMJuI0g/present?hl=en_US&amp;pli=1#slide=id.p">presentation about why should we care about html5, css3 and JavaScript</a>. Since Plamen is more concentrated on JavaScript, there are less arguments and links <span class='keyword'>for</span> html5 and css3, but still it's a very strong research regarding the latest tendencies. </p> ]]></description>
					<pubDate>Mon, 12 Dec 2011 00:00:00 EET</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/html/explaining-web-to-hard-programmers</guid>
					<link>http://radoslavpopov.com/html/explaining-web-to-hard-programmers</link>
					<category>html</category>
				</item>
							<item>
					<title>The Next Five Years Will Be Very Exciting</title>
					<description><![CDATA[ <p>In May 2010, the (now former) Google employee <a href="http://blog.codinginparadise.org/">Brad Neuberg</a> gave an amazing presentation about the <span class='keyword'>new</span> and emerging technologies in web development. The name of the topic is <q>HTML5 and the Future of the Web</q>, but don't let <span class='keyword'>this</span> title fool you - it's not dedicated only to HTML5 but also to CSS3, SVG and the <span class='keyword'>new</span> JavaScript APIs. According to Brad: </p>
<blockquote>
<p>HTML5 = Next Generation Features <span class='keyword'>for</span> Modern Web Development</p>
</blockquote>
<p>Fortunately, a high quality video is uploaded on youtube. Although May 2010 is now way behind us, <span class='keyword'>this</span> video is still a brilliant overview of what's going on today.  Before seeing it, I didn't believed that someone can explain all <span class='keyword'>this</span> stuff in less than an hour, but Brad proved me wrong. And he did it with style. </p>
<p>Here are the topics mentioned in the video and the quotes that impressed me the most:</p>
<ul>
<li><strong>New JavaScript selectors</strong> - it's a sort of what jQuery gives you. You can put an arbitrary CSS selector;</li>
<li><strong>Web Storage</strong> - It's really easy to be used, and it just persists;</li>
<li><strong>Web SQL Database</strong> - When simple key-value pair isn't enough, another part of HTML5 is a real SQL database;</li>
<li><strong>Application Cache API</strong>;</li>
<li><strong>Geolocation</strong>;</li>
<li><strong>Web Workers</strong> - they are not threads, but they kind of act like them;</li>
<li><strong>Drag And Drop</strong>;</li>
<li><strong>New Semantic Tags</strong> - the nice thing is that it keeps your mark-up more semantic, it helps search engines [...] and you're also making your page more maintainable;</li>
<li><strong>New link relations</strong>;</li>
<li><strong>Microdata</strong> - it's not trying to be artificial intelligence mark-up language, and it's learning from a lot of the lessons from the last 15 years. Right now Google will actually see some Microdata mark-ups <span class='keyword'>for</span> events, reviews, in order to get better search results;</li>
<li><strong>ARIA attributes</strong> - one problem with jQuery UI, Dojo UI, is that screen readers can't work with them. ARIA is a way to add a little more of extra information, so screen readers know that a jQuery UI component that is a tree... is a tree;</li>
<li><strong>New form field types</strong> - we don't have to do <span class='keyword'>this</span> with JavaScript. So a lot of HTML5 is, again... get things out of the JavaScript that don't really belong there, get them back in the browser;</li>
<li><strong>Audio</strong> and <strong>Video</strong> - <span class='keyword'>this</span> is really in the browser, so we can add CSS reflection (and other stuff);</li>
<li><strong>Canvas</strong>;</li>
<li><strong>SVG</strong> - HTML5 says you can now drop these tags into the normal html;</li>
<li><strong>Selectors</strong> - CSS gives you more of them (selectors) based on what people have asked for;</li>
<li><strong>Fonts</strong> - it's actually from CSS 2.1 but it's finally ariving after 15 years;</li>
<li><strong>Text wrapping</strong> - you have no idea how much pain people have gone trough, having to use server-side solution to achieve <span class='keyword'>this</span>;</li>
<li><strong>Columns</strong> - something that used to be a pain in the but to do; you don't have to be a wizzard to do things that everyone needs to do;</li>
<li><strong>Text stroke</strong>;</li>
<li><strong>Opacity</strong> - <span class='keyword'>this</span> used to require custom made images;</li>
<li><strong>HSL</strong> - the reason that matters is humans don't think of colors in terms how rgb asked you to think of colors;</li>
<li><strong>Rounded corners</strong> - it's amazing how common things used to be so hard;</li>
<li><strong>Gradients</strong> - with great power comes great responsibility;</li>
<li><strong>Text shadows</strong>;</li>
<li><strong>Background sizing and multiple backgrounds</strong> - again, you don't have to spend many hours in front of Photoshop;</li>
<li><strong>Transition and Transforms</strong> - these can replace a lot of JavaScript.</li></ul>
<p>In general, two phrases by Brad Neuberg are also worth mentioning: </p>
<blockquote>
<p>It's great time to be a web developer</p>
</blockquote>
<p>and</p>
<blockquote>
<p>The next five years will be very exciting</p>
</blockquote>
<p>The slides can be found on <a href="http://slides.html5rocks.com/">slides.html5rocks.com</a>. It seems that they update the information from time to time with things that are missed, or had not existed, during the talk, which is a great way to keep yourself informed about what's going on in the constantly changing world of HTML5, CSS3 and JavaScript. Some of the <span class='keyword'>new</span> topics are IndexedDB, Web Sockets, Desktop Drag-In (File API), Desktop Drag-Out, FileSystem APIs, Device Orientation, Speech Input, Markup <span class='keyword'>for</span> applications, Form field types on mobile, Border image, Flexible Box Model, Custom data-* attributes, Element.classList, History API.</p>
<p>Enjoy the video. </p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/nJRH1ljFu84"></iframe></p> ]]></description>
					<pubDate>Mon, 26 Sep 2011 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/html5/the-next-five-years-will-be-very-exciting</guid>
					<link>http://radoslavpopov.com/html5/the-next-five-years-will-be-very-exciting</link>
					<category>html5</category>
				</item>
							<item>
					<title>Beyond Expertise</title>
					<description><![CDATA[ <blockquote>
<p>Finally, after all <span class='keyword'>this</span> talk about expertise and becoming more expert, what lies beyond the expert? In an oddly circular way, the most sought-after thing you want to achieve after becoming an expert is...the beginner’s mind.</p>
<p>The professional kiss of death <span class='keyword'>for</span> an expert is to act like one. Once you believe in your own expertness, you close your mind to possibilities. You stop acting on curiosity. You may begin to resist change in your field <span class='keyword'>for</span> fear of losing authority on a subject you’ve spent so long mastering. Your own judgment and views, instead of supporting you, can imprison you.</p>
<p>I’ve seen a lot of <span class='keyword'>this</span> over the years. Folks invest heavily in some language, say, Java, or C++ before it. They get all the certifications; they memorize the fifteen lineal feet of books on the API and related tools. Then some <span class='keyword'>new</span> language comes around that lets them write programs much more concisely and more intuitively, test more thoroughly, achieve greater concurrency more easily, and so on. And they don’t want any part of it. They’ll spend more energy deriding the newcomer than in seriously evaluating it <span class='keyword'>for</span> their needs.</p>
<p>That’s not the kind of expert you want to become.</p>
<p>Instead, always keep a “beginner’s” mind. Ask “what if?” You want to emulate a child’s insatiable curiosity, full of wonder and amazement. [...]</p>
<p>Approach learning without preconceived notions, prior judgment, or a fixed viewpoint. See things exactly as they are—just as a child would.</p>
<p>Wow. This is cool. I wonder how it works? What is it? </p>
<p><cite><a href="http://pragprog.com/book/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning: Refactor Your Wetware</a></cite></p>
</blockquote> ]]></description>
					<pubDate>Thu, 22 Sep 2011 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/attitude/beyond-expertise</guid>
					<link>http://radoslavpopov.com/attitude/beyond-expertise</link>
					<category>attitude</category>
				</item>
							<item>
					<title>Classical OOP in JavaScript</title>
					<description><![CDATA[ <p>There are two ways to look at the Object-oriented programming when it comes to JavaScript. The first one is to think in terms of <strong>classes and instances</strong> (the classical OOP), and the second one - only in terms of <strong>objects</strong> (the prototypal OOP). It is hard <span class='keyword'>for</span> Java, C# and C++ developers not to think about classes, since the <em>classical</em> OOP, as we all know it from these languages, relies entirely on defining the instance structure through classes and interfaces. Thus, I will first make some notes on it on <span class='keyword'>this</span> article.</p>
<h2> Classical OOP</h2>
<p>In classical OOP, we define a <strong>class</strong> via the keyword <strong><span class='keyword'>function</span></strong>. The same keyword is used to define public and private, static and instance methods. It sounds complicated, and it really is. But the reason <span class='keyword'>for</span> <span class='keyword'>this</span> is that the classical OOP in JavaScript is only a patch. </p>
<p>The following is an example of a fully exposed class:</p>
<pre><span class='keyword'>var</span> Book = <span class='keyword'>function</span>(isbn, title, author) { 
	<span class='keyword'>this</span>.isbn = isbn; 
	<span class='keyword'>this</span>.title = title <span class='keyword'>||</span> 'No title specified'; 
	<span class='keyword'>this</span>.author = author <span class='keyword'>||</span> 'No author specified';
}
// public instance method
Book.prototype.display = <span class='keyword'>function</span>() { ... };
// public static method
Book.convertToTitleCase = <span class='keyword'>function</span>(string) { ... }; 
</pre>
<p>Instances are created via the <strong><code>new</code></strong> keyword, as you may guess. The anonymous <span class='keyword'>function</span> is the class constructor. </p>
<p>All instances of the <code>Book</code> class provides three public properties (<code>isbn</code>, <code>title</code> and <code>author</code>) and a public method (<code>display</code>). The prototype property is used to attach a method to all instances of a given class (the prototype property is still to be discussed in details).</p>
<p>There is nothing interesting about the fully exposed classes, so we are getting straight to the private members. </p>
<pre><span class='keyword'>var</span> Book = <span class='keyword'>function</span>(isbn, title, author) { 
	// private attributes
	<span class='keyword'>var</span> isbn, title, author; 
	// private method
	<span class='keyword'>function</span> checkIsbn(isbn) { ... }
	// public privileged method
	<span class='keyword'>this</span>.setTitle = <span class='keyword'>function</span>(newTitle) { 
		title = newTitle <span class='keyword'>||</span> 'No title specified'; 
	}; 
};
// public non-privileged method
Book.prototype.display = <span class='keyword'>function</span>() { ... }; 
</pre>
<p>This time, <code>isbn</code>, <code>title</code> and <code>author</code> are private attributes. <code>Book</code> is in fact a <a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures">closure</a> <span class='keyword'>for</span> the public <code>setTitle</code> method. Thus, the <code>setTitle</code> method has access to the local variables of its closure. Using closures, we can imitate private attributes and methods. </p>
<p>Two types of public methods can be declared in JavaScript, in contrast with Java. This is not some native feature of the language, it's just that attaching a method to the <code><span class='keyword'>this</span></code> object inside the class (the closure) makes the method (called privileged method) see the private members, and attaching a method to the prototype property of the class is done outside the class (the closure) and that's why the method (called non-privileged method) does not see the private members. There are no non-privileged methods in Java. </p>
<p>Now, how do we declare private static members? The most famous example about a static property is a counter that counts all instances. </p>
<pre><span class='keyword'>var</span> Book = (<span class='keyword'>function</span>() {
		// private static attribute
		<span class='keyword'>var</span> instances = 0;
		// class constructor
		<span class='keyword'>return</span> <span class='keyword'>function</span>() { 
			instances++;
		}
})();

<span class='keyword'>var</span> book1 = <span class='keyword'>new</span> Book(); // Book.instances == 1
<span class='keyword'>var</span> book2 = <span class='keyword'>new</span> Book(); // Book.instances == 2
</pre>
<p>Note the <strong><code>()</code></strong> at the end of the <span class='keyword'>function</span> declaration. This is a self-executing <span class='keyword'>function</span>. The question is what happens to the <code>Book</code> variable. Our self-executing <span class='keyword'>function</span> returns another <span class='keyword'>function</span>. It is assigned to the <code>Book</code>. The idea is that you cannot execute the outer <span class='keyword'>function</span> any more (it does not have a name). So the local variable <code>instances</code> is initialized only once (<span class='keyword'>this</span> is exactly the behavior of the static members within a class). But its value can be changed by calling the inner <span class='keyword'>function</span>. Remember, the inner <span class='keyword'>function</span> has access to the local variables of its closure. You call it by instantiating the <code>Book</code> class. </p>
<p>So, speaking in terms of the classical OOP, <code>Book</code> is a class, <code>instances</code> is a private static property, and we have a constructor inside the <code>Book</code> class. </p>
<p>Static methods are declared in the same way:</p>
<pre><span class='keyword'>var</span> Book = (<span class='keyword'>function</span>() {
	// private static method
	<span class='keyword'>function</span> checkISBN(isbn) { ... }
	// class constructor
	<span class='keyword'>return</span> <span class='keyword'>function</span>(isbn) { 
		checkISBN(isbn);
		...
	}
})();
// public static method
Book.convertToTitleCase = <span class='keyword'>function</span>(string) { ... }
</pre>
<p>At <span class='keyword'>this</span> moment you should have noticed that we used different structures to declare static members and instance members - self-executing <span class='keyword'>function</span> and a &quot;simple&quot; closure. So how do we combine instance and static members? It's simple, we use the structure <span class='keyword'>for</span> the static members (a self-executing <span class='keyword'>function</span>) and declare the instance members inside the returned inner <span class='keyword'>function</span> (the constructor):</p>
<pre><span class='keyword'>var</span> Book = (<span class='keyword'>function</span>() {
	// private static method
	<span class='keyword'>function</span> checkISBN(isbn) { ... }
	// class constructor + instance members
	<span class='keyword'>return</span> <span class='keyword'>function</span>(isbn) { 
		// constructor code
		checkISBN(isbn);
		// private method
		<span class='keyword'>var</span> isbnToCountry = <span class='keyword'>function</span>() { ... }
		// public privileged method
		<span class='keyword'>this</span>.getCountry = <span class='keyword'>function</span>() { ... }
	}
})();
</pre>
<p>In the end, what is an Object-oriented paradigm without <strong>inheritance</strong>? </p>
<pre><span class='keyword'>function</span> Person(name) {
	<span class='keyword'>this</span>.name = name;
}
Person.prototype.getName = <span class='keyword'>function</span>() {
	<span class='keyword'>return</span> <span class='keyword'>this</span>.name;
}
</pre>
<p>We need an <code>Author</code> class that extends the <code>Person</code>. We do it in that way:</p>
<pre><span class='keyword'>function</span> Author(name, books) {
	Person.call(<span class='keyword'>this</span>, name); 
	<span class='keyword'>this</span>.books = books; 
}
Author.prototype = <span class='keyword'>new</span> Person(); 
Author.prototype.constructor = Author; 
</pre>
<p>Several things happen here. First, we don't have a native method to declare that a class extends another one. We need to rely on the <strong>prototype chaining</strong>. When we call a member on an object, the interpreter (the browser) first checks whether the method is available in <span class='keyword'>this</span> particular object. If not found, the special prototype property is used. If the value of the prototype property is object, the member is searched in <span class='keyword'>this</span> object. And the process continues to the top (while the prototype of some object in the chain is <code>null</code>). </p>
<p>When an object is created via the <strong><code>new</code></strong> keyword, a secret link is created between the <span class='keyword'>new</span> object and its class (the class is in fact a <span class='keyword'>function</span>, and all <span class='keyword'>function</span>s in JavaScript are objects). This explains why public methods are added to the instances of a particular class by adding them to the prototype property of the class. Now, get back to the beginning of the Classical OOP section to once again see the examples (and <span class='keyword'>this</span> time think only in terms of objects to understand the prototype chaining and why public instance methods are defined by attaching them to the prototype property of the &quot;class&quot;). </p>
<p>Let's get back to out <code>Author</code>. We want all members of <code>Person</code> to be available to instances of <code>Author</code>. So we link the prototype property of <code>Author</code> to a <span class='keyword'>new</span> Person object. This looks strange to a classical programmer, but remember, we have to attach an actual object, and <code><span class='keyword'>new</span> Person</code> is exactly that. </p>
<p>For every given <span class='keyword'>function</span> <code>f</code>, <code>f.prototype.constructor</code> points by default to the <code>f</code> itself. When the <code>new</code> operator is used, the interpreter looks <span class='keyword'>for</span> the value of the <code>f.prototype.constructor</code>. We have just changed it by changing the entire prototype property, so we need to correct the behavior of the <code>new</code> operator. </p>
<p>Finally, we need to call the super class constructor. This is also complicated. The <em>magic</em> <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call"><span class='keyword'>function</span> call</a> is used. It changes the <strong>context</strong> of the <code>Person</code> <span class='keyword'>function</span> to the context inside the <code>Author</code> <span class='keyword'>function</span>. I.e. the <code><span class='keyword'>this</span></code> keyword within <code>Person</code> points to the same object as the <code><span class='keyword'>this</span></code> keyword within the <code>Author</code>. </p>
<p>Because of all these efforts, the string 'Dustin Diaz' is returned by the following code:</p>
<pre>(<span class='keyword'>new</span> Author('Dustin Diaz', ['Pro JavaScript Design Patterns'])).getName();
</pre>
<p>Nice. Now let's encapsulate all the inheritance logic inside a global <span class='keyword'>function</span> <strong><code>extend</code></strong>: </p>
<pre><span class='keyword'>function</span> extend(subClass, superClass) {
	subClass.prototype = <span class='keyword'>new</span> superClass();
	subClass.prototype.constructor = subClass;
	subClass.superClass = superClass;
}
</pre>
<p>This works nice, except that may not be so efficient as <span class='keyword'>this</span> one:</p>
<pre><span class='keyword'>function</span> extend(subClass, superClass) {
	<span class='keyword'>var</span> temp = <span class='keyword'>function</span>() {};
	temp.prototype = superClass.prototype;
	subClass.prototype = <span class='keyword'>new</span> temp();
	subClass.prototype.constructor = subClass;
	subClass.superClass = superClass;
}
</pre>
<p>What we do here is to avoid instantiating the super class and in the same time preserve the prototype chain. As a result we can write the following code:</p>
<pre><span class='keyword'>function</span> Author(name, books) {
	Author.superClass.call(<span class='keyword'>this</span>, name); 
	<span class='keyword'>this</span>.books = books; 
}
extend(Author, Person);
 </pre>
<p>I personally prefer to write <code>Author.extends(Person)</code> instead of <code>extend(Author, Person)</code>. It even sounds better when you pronounce it (try to pronounce both loud). And it easy to be implemented. Just add a method <code>extends</code> on every <span class='keyword'>function</span>:</p>
<pre>Function.prototype.extends = <span class='keyword'>function</span>(superClass) {
	<span class='keyword'>var</span> temp = <span class='keyword'>function</span>() {};
	temp.prototype = superClass.prototype;
	<span class='keyword'>this</span>.prototype = <span class='keyword'>new</span> temp();
	<span class='keyword'>this</span>.prototype.constructor = <span class='keyword'>this</span>;
	<span class='keyword'>this</span>.superClass = superClass;
}
</pre>
<p>By <span class='keyword'>this</span> time you should know how to declare and instantiate classes, how to define private and public, static and instance members, and how to extend one class from another. The true power of Object-oriented programming is seen when you apply the concepts to some design pattern. <strong>Singleton</strong> is used more in JavaScript in comparison with any other language. So here is a quick example:</p>
<pre><span class='keyword'>var</span> multipleEdit = <span class='keyword'>function</span>() {
	<span class='keyword'>var</span> CHECKBOX_CONTAINER_ID = 'params';
	<span class='keyword'>var</span> checkboxes;
	<span class='keyword'>function</span> initCheckboxes() { ... };
	<span class='keyword'>function</span> attachClickEvents() { ... };
	...
	<span class='keyword'>return</span> {
		install: <span class='keyword'>function</span>() { ... };
		selectRecord: <span class='keyword'>function</span>() { ... };
	}
}
</pre>
<p>This is a reusable module <span class='keyword'>for</span> checkbox handling. There is some complex logic here, but the bottom line is that we want to provide only two public methods: <code>install</code> (to initialized the script) and <code>selectRecord</code> (in case someone wants to trigger the event registration from within the html). Hence, we declare these methods inside a <span class='keyword'>return</span> statement. Again, it may looks like a magic <span class='keyword'>for</span> the most programmers who come from Java or C++. In order to understand the structure, just think in terms of JavaScript. <code>multipleEdit</code> is just a name of an anonymous <span class='keyword'>function</span>. All variables and <span class='keyword'>function</span>s declared inside <span class='keyword'>this</span> <span class='keyword'>function</span> are not accessible outside. The <span class='keyword'>function</span> returns another variable to the outside environment: an object with two properties: <code>install</code> of type <span class='keyword'>function</span>, and <code>selectRecord</code> of type <span class='keyword'>function</span>. The tricky part is that <span class='keyword'>this</span> object is created dynamically, using the <code>{}</code> notation. As a result, we can write the following code to initialize the script: <code>multipleEdit.install()</code>. </p>
<h2> Prototypal OOP</h2>
<p>In the prototypal OOP, you directly create an object instead of defining its structure through a class. Then, you reuse it to create <span class='keyword'>new</span> objects and rely on the power of the prototype chaining. An article on prototype OOP in JavaScript is coming soon. </p>
<h2> Resources</h2>
<p>Most of the examples in <span class='keyword'>this</span> article are from the book <a href="http://www.dustindiaz.com/pro-javascript-design-patterns/">Pro JavaScript Design Patterns</a> by Dustin Diaz and Ross Harmes. I really liked the first part of the book, explaining both ways to think of OOP in JavaScript. </p> ]]></description>
					<pubDate>Fri, 03 Dec 2010 00:00:00 EET</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/javascript/classical-oop-in-javascript</guid>
					<link>http://radoslavpopov.com/javascript/classical-oop-in-javascript</link>
					<category>javascript</category>
				</item>
							<item>
					<title>How To Draw The Attention Of The Audience</title>
					<description><![CDATA[ <p>One of the best places I've ever seen to <a href="http://ejohn.org/apps/learn/">learn advanced JavaScript is on ejohn.org</a>. There are several reasons <span class='keyword'>for</span> it, but what I want to mention here is the first slide (after the summary). <strong>Our goal</strong>! Determining a <strong>goal</strong> <span class='keyword'>for</span> your <strong>audience</strong> is the best way to draw attention to the end of any presentation. In <span class='keyword'>this</span> case the effect is even bigger because the audience will have found out till the end of the introduction whether the information is relevant to them, thus whether they are interested to listen / read. </p>
<p>I am amazed how many lecturers failed to do that simple trick and therefore lose connection with the audience. </p> ]]></description>
					<pubDate>Sat, 22 May 2010 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/presentations/javascript-presentation-how-to-draw-attention-of-audience</guid>
					<link>http://radoslavpopov.com/presentations/javascript-presentation-how-to-draw-attention-of-audience</link>
					<category>presentations</category>
				</item>
							<item>
					<title>Progressive Enhancement Cannot Be Applied To html5 Layouts</title>
					<description><![CDATA[ <p>Let me first make <span class='keyword'>this</span> clear: <em>each time you <strong>fix</strong> something <span class='keyword'>for</span> a certain browser, you are not applying progressive enhancement</em>. Progressive enhancement is all about building <span class='keyword'>for</span> the less capable first and enhance the experience <span class='keyword'>for</span> those using the latest modern browsers. So, any type of fixes are useless. If you use fixes, you might be applying graceful degradation or, more likely, you may just be hacking around in order to workaround the differences across the browsers and to make everything look and feel the same. </p>
<p>One of the great features of <a href="http://radoslavpopov.com/tags/html5/">html5</a> is the <span class='keyword'>new</span> semantic tags. Like <code>section</code>, <code>article</code>, <code>aside</code>, <code>footer</code>, etc. Let's see how we can build a <span class='keyword'>new</span> layout using them. First of all, we have to make them block-level elements with css since they will behave as inline in each browser that do not understand them. So we <strong>fix</strong> the fact that these browsers do not support html5 semantic tags. Oops, I used the word fix, that's an indication we're not applying progressive enhancement. Ok, that's a tiny little fix so we can ignore it. Now, another obstacle is that Internet Explorer cannot apply a style to elements it doesn't know. So we're using the <a href="http://ejohn.org/blog/html5-shiv/">html5 shiv</a> to create the elements in the DOM Tree and to <strong>fix</strong> <span class='keyword'>this</span> bug in IE. Oops, another fix. I'm not going to continue, I believe you get my point. </p>
<p>Ok, but what about the degradation of our future highly semantic markup? When you apply these fixes, another issue to worry about is what happens on browsers that do not support css. All these block-level elements becomes inline and the page looks messy (remember the idea of the <a href="http://naked.dustindiaz.com/">CSS Naked Day</a>?) The same way as <span class='keyword'>if</span> you use only spans to build the layout. Or what happens to IE with JavaScript turned off. It still cannot see the styles related to the <span class='keyword'>new</span> elements. So, our degradation is obviously  not graceful, it is, to be honest, painful to watch. </p>
<p>The fact is, html, no matter which version, is not related to the user experience in any way on a given web page. It describes the data on the web, it marks it up. That's it. No visualization, no behavior. So, how can we build html5 layouts using progressive enhancement? Which is the basic technology we can use before it to assure wide support? Yup, there isn't any. Of course, we can build our layouts in the old way, but then we are not really using html5, only these features that work across the different browsers, like the short doctype, short charset, etc. That's a kind of compromise, it's neither progressive enhancement nor graceful degradation. </p>
<p>A great example of <a href="http://radoslavpopov.com/tags/html5/">html5</a> and graceful degradation is <a href="http://camendesign.com/code/video_for_everybody">Video <span class='keyword'>for</span> Everybody! on camendesign.com</a>. It uses html5 video features, then it fails to QuickTime <span class='keyword'>if</span> your browser is not aware of html5, then it fails to flash, then it fails to image. But can't we reverse the process? Can't we build <span class='keyword'>for</span> the one that is unable to see video by any mean and then add flash, QuickTime and in the end - html5? I think it cannot be done right now, but it's still a not explored field. I might be wrong...</p> ]]></description>
					<pubDate>Tue, 20 Apr 2010 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/html/progressive-enhancement-cannot-be-applied-to-html5-layouts</guid>
					<link>http://radoslavpopov.com/html/progressive-enhancement-cannot-be-applied-to-html5-layouts</link>
					<category>html</category>
				</item>
							<item>
					<title>html5 Videos On Youtube</title>
					<description><![CDATA[ <p>Go to <a href="http://www.youtube.com/html5">http://www.youtube.com/html5</a>, click on <em>Join the HTML5 Beta</em> link and search <span class='keyword'>for</span> a video. You have to use a web browser that supports the html5 video tag and the youtube video format, which pretty much limits you to Safari 4 or Chrome 4 by the time <span class='keyword'>this</span> article is published (Update: Firefox 4 is now on the list). </p>
<p><a href="http://meyerweb.com/eric/thoughts/2010/04/07/turning-web-video-on-its-head/">Eric Meyer demonstrates an interesting flexibility</a> when html5 is used instead of flash.</p> ]]></description>
					<pubDate>Thu, 15 Apr 2010 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/html/html5-videos-on-youtube</guid>
					<link>http://radoslavpopov.com/html/html5-videos-on-youtube</link>
					<category>html</category>
				</item>
							<item>
					<title>Version 5</title>
					<description><![CDATA[ <p>If someone follows the URL to your web site and don't see a typical blog there, it looks ridiculous, preposterous, even tasteless. Of course what people think has never cause me to do something different from what I had in mind in first place. But it has made me think of the real cause I've changed the content, layout and the look and feel of radoslavpopov.com so many times in the last several years. </p>
<p>Through the years I've used <span class='keyword'>this</span> place to improve my skills as a web developer. This was the place I've first learned how to use tables to structure my content... and later to use <code>div</code>s <span class='keyword'>for</span> everything I could mark up... and later to use semantic mark-up, and how to separate content, styling and behavior... and what is unobtrusive JavaScript... and so on. </p>
<p>If we met each other in the last two years it has a good chance that you know my daily work is not related to Front-end development any longer. And I missed some epic events in the scope. The release of IE8. God help me <span class='keyword'>if</span> I need to build even the easiest layout and something goes wrong. The emerging css3 and it's support in most modern browsers. All the buzz around html5. The next big thing - fonts in modern web design. </p>
<p>One sunny day I got sick, stayed at home and decided that <span class='keyword'>this</span> tendency needs to be broken. I cannot afford to waste years in gained knowledge because of laziness and to become the typical server-side developer, one I used to hate so much in the near past. Besides that, I love Front-end technologies, it's just that... well... I've forgotten about <span class='keyword'>this</span> love lately. </p>
<p>So, <span class='keyword'>this</span> is the result - a brand <span class='keyword'>new</span> version of my web site (I called it v5 in accordance to the html5, although it should be near 10 <span class='keyword'>if</span> I'd counted correctly).  It will continue to serve as a place to gain knowledge about one of the fields I love the most. </p>
<p>Btw, don't be too disappointed <span class='keyword'>if</span> you've opened the source only to see the old looong boring doctype. There is a reason I'm not moving too fast to the html5, but <span class='keyword'>this</span> is a topic <span class='keyword'>for</span> a future post. </p> ]]></description>
					<pubDate>Sun, 04 Apr 2010 00:00:00 EEST</pubDate>
					<author>nospam@radoslavpopov.com (Radoslav Popov)</author>
					<guid isPermaLink="true">http://radoslavpopov.com/general/version-5</guid>
					<link>http://radoslavpopov.com/general/version-5</link>
					<category>general</category>
				</item>
					</channel>
	</rss>
