<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: JavaScript Is Not &#8220;Truly&#8221; Object Oriented</title>
	<atom:link href="http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/</link>
	<description>» scrumptions blog &#038; code » nothing more, nothing less</description>
	<lastBuildDate>Thu, 29 Jul 2010 18:30:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Eric Hamilton</title>
		<link>http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/comment-page-1/#comment-6916</link>
		<dc:creator>Eric Hamilton</dc:creator>
		<pubDate>Tue, 27 Jul 2010 21:37:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.engfers.com/?p=276#comment-6916</guid>
		<description>Javascript is very commonly misunderstood in this way. It actually does support encapsulation via enclasures. JQuery makes heavy use of enclosures - only exposing what is necessary to the global namespace, while the bulk of the internal workings are safely hidden away where no other scripts running on the same page can get at them. There&#039;s a good introduction to tutorials in this excerpt from &quot;Secrets of the Javascript Ninjas&quot; - http://mpathirage.com/files/javascript_ninja/JavaScriptNinja_ch3_Article2.pdf

Here&#039;s the language construct you need to familiarize yourself with to do encapsulation:

var myNamespace = (function(){ // assign the return value of an anonymous function to a var in the global space
function myNamespace(){
// Initialize
}
var hiddenStuff = &quot;my secret&quot;; // anything you define here will be hidden from the global scope.
return myNamespace;
})();

As for polymorphic inheritance, it is actually easy to inherit from an object, and override a parent method.

Parent = function() {
    // bunch of properties
}
Parent.someMethod = function () {
   // some behavior to override
}

var parentObj = new Parent();
var childObj = Object.create(parentObj);
childObj.someMethod = function () {
    // new behavior for child
}

Of course, you can also do all this within the child object&#039;s constructor, and then just do: 

var childObj = new ChildObj();

When you call childObj.someMethod(); you&#039;ll get the child version, not the parent&#039;s prototype version.

Javascript is certainly a different way of working, but once you wrap your brain around prototypical inheritance, you&#039;ll see that: 

1) Javascript can mimic class-based inheritance models, complete with encapsulation and polymorphic inheritance.

2) Prototypical inheritance is actually less verbose and more expressive than class-based inheritance, and...

3) Class-based inheritance cannot easily mimic prototypical inheritance.

In other words - Javascript has BETTER OO than C++ and Java.

If you want to criticize Javascript, there are plenty of valid attacks you can make - for example, Javascript lacks fast matrix manipulation capabilities, because it lacks support for predictable array element lengths (array elements with strong types). It also only supports one number type, (IEEE float), and that number type sucks for doing even basic floating point math.

Until these REAL problems are fixed, we&#039;re never going to see, for example, a high-performance 3D game engine written in Javascript running in the browser. (Although there are people doing 2 1/2 D game engines similar to the original Doom engine even with these limitations).</description>
		<content:encoded><![CDATA[<p>Javascript is very commonly misunderstood in this way. It actually does support encapsulation via enclasures. JQuery makes heavy use of enclosures &#8211; only exposing what is necessary to the global namespace, while the bulk of the internal workings are safely hidden away where no other scripts running on the same page can get at them. There&#8217;s a good introduction to tutorials in this excerpt from &#8220;Secrets of the Javascript Ninjas&#8221; &#8211; <a href="http://mpathirage.com/files/javascript_ninja/JavaScriptNinja_ch3_Article2.pdf" rel="nofollow">http://mpathirage.com/files/javascript_ninja/JavaScriptNinja_ch3_Article2.pdf</a></p>
<p>Here&#8217;s the language construct you need to familiarize yourself with to do encapsulation:</p>
<p>var myNamespace = (function(){ // assign the return value of an anonymous function to a var in the global space<br />
function myNamespace(){<br />
// Initialize<br />
}<br />
var hiddenStuff = &#8220;my secret&#8221;; // anything you define here will be hidden from the global scope.<br />
return myNamespace;<br />
})();</p>
<p>As for polymorphic inheritance, it is actually easy to inherit from an object, and override a parent method.</p>
<p>Parent = function() {<br />
    // bunch of properties<br />
}<br />
Parent.someMethod = function () {<br />
   // some behavior to override<br />
}</p>
<p>var parentObj = new Parent();<br />
var childObj = Object.create(parentObj);<br />
childObj.someMethod = function () {<br />
    // new behavior for child<br />
}</p>
<p>Of course, you can also do all this within the child object&#8217;s constructor, and then just do: </p>
<p>var childObj = new ChildObj();</p>
<p>When you call childObj.someMethod(); you&#8217;ll get the child version, not the parent&#8217;s prototype version.</p>
<p>Javascript is certainly a different way of working, but once you wrap your brain around prototypical inheritance, you&#8217;ll see that: </p>
<p>1) Javascript can mimic class-based inheritance models, complete with encapsulation and polymorphic inheritance.</p>
<p>2) Prototypical inheritance is actually less verbose and more expressive than class-based inheritance, and&#8230;</p>
<p>3) Class-based inheritance cannot easily mimic prototypical inheritance.</p>
<p>In other words &#8211; Javascript has BETTER OO than C++ and Java.</p>
<p>If you want to criticize Javascript, there are plenty of valid attacks you can make &#8211; for example, Javascript lacks fast matrix manipulation capabilities, because it lacks support for predictable array element lengths (array elements with strong types). It also only supports one number type, (IEEE float), and that number type sucks for doing even basic floating point math.</p>
<p>Until these REAL problems are fixed, we&#8217;re never going to see, for example, a high-performance 3D game engine written in Javascript running in the browser. (Although there are people doing 2 1/2 D game engines similar to the original Doom engine even with these limitations).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Alexander</title>
		<link>http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/comment-page-1/#comment-4276</link>
		<dc:creator>Michael Alexander</dc:creator>
		<pubDate>Thu, 24 Sep 2009 23:38:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.engfers.com/?p=276#comment-4276</guid>
		<description>Dear Mr. Caligula

I find your position untenable. If we all attach our own meaning and definitions to words, what&#039;s the point of having a dictionary and how do we communicate efficiently and effectively with one another?

I&#039;m not familiar with Small Talk. Are you saying it doesn&#039;t support encapsulation and dynamic binding?

Re your last question, if it was sincere and not rhetorical, a scripting language is a language used to control another piece of software, in the case of JavaScript, the software is the browser.


Peace</description>
		<content:encoded><![CDATA[<p>Dear Mr. Caligula</p>
<p>I find your position untenable. If we all attach our own meaning and definitions to words, what&#8217;s the point of having a dictionary and how do we communicate efficiently and effectively with one another?</p>
<p>I&#8217;m not familiar with Small Talk. Are you saying it doesn&#8217;t support encapsulation and dynamic binding?</p>
<p>Re your last question, if it was sincere and not rhetorical, a scripting language is a language used to control another piece of software, in the case of JavaScript, the software is the browser.</p>
<p>Peace</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Caligula</title>
		<link>http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/comment-page-1/#comment-500</link>
		<dc:creator>Caligula</dc:creator>
		<pubDate>Fri, 19 Sep 2008 12:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.engfers.com/?p=276#comment-500</guid>
		<description>&gt; I am tired of people writing stuff in/about JavaScript and calling it Object Oriented without explaining the difference between true object-oriented languages and scripting languages like JavaScript.

And I&#039;m tired of people believing that OO means only one thing.

Is Smalltalk OO? Of course it is--but most implementations have no concept of private variables, instead relying on convention. There&#039;s also instVarAt: and instVarAt:put: messages.

Is Self OO? Of course it is--it&#039;s also a prototypal-inheritance language.

(And what&#039;s a &quot;scripting language&quot;?)</description>
		<content:encoded><![CDATA[<p>&gt; I am tired of people writing stuff in/about JavaScript and calling it Object Oriented without explaining the difference between true object-oriented languages and scripting languages like JavaScript.</p>
<p>And I&#8217;m tired of people believing that OO means only one thing.</p>
<p>Is Smalltalk OO? Of course it is&#8211;but most implementations have no concept of private variables, instead relying on convention. There&#8217;s also instVarAt: and instVarAt:put: messages.</p>
<p>Is Self OO? Of course it is&#8211;it&#8217;s also a prototypal-inheritance language.</p>
<p>(And what&#8217;s a &#8220;scripting language&#8221;?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Main Reason For JavaScript Unreadability at engfer(s)</title>
		<link>http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/comment-page-1/#comment-444</link>
		<dc:creator>The Main Reason For JavaScript Unreadability at engfer(s)</dc:creator>
		<pubDate>Fri, 12 Sep 2008 13:33:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.engfers.com/?p=276#comment-444</guid>
		<description>[...] we said in another article &#8216;JavaScript Is Not &#8220;Truly&#8221; Object Oriented&#8216;, the difference between prototypal and object-based inheritance is the same difference [...]</description>
		<content:encoded><![CDATA[<p>[...] we said in another article &#8216;JavaScript Is Not &#8220;Truly&#8221; Object Oriented&#8216;, the difference between prototypal and object-based inheritance is the same difference [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
