<?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"
	>
<channel>
	<title>Comments on: Advanced Users May Choose</title>
	<atom:link href="http://nodename.com/blog/2008/01/13/advanced-users-may-choose/feed/" rel="self" type="application/rss+xml" />
	<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/</link>
	<description></description>
	<pubDate>Thu, 20 Nov 2008 23:07:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: alan</title>
		<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-119750</link>
		<dc:creator>alan</dc:creator>
		<pubDate>Sun, 27 Apr 2008 23:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-119750</guid>
		<description>Dennis,

The advantage of saying
&lt;pre&gt;
SomeClass.prototype.variable = value;
&lt;/pre&gt;
is that it's completely dynamic -- the variable does not have to have been declared as a property in SomeClass.as, and it can be set by any code outside the class -- and it can be accessed as though it were a property of any instance of SomeClass or of any derived class -- either by declaring the class dynamic, or by using the bracket notation:
&lt;pre&gt;
someClassInstance["variable"]
&lt;/pre&gt;

A protected variable would have to have been declared in the class file, would have to be set on every instance that needs it, and cannot be accessed from unrelated code.

To be more specific about a use case, consider a specific function that a game character must execute whenever he arrives at any Flower, whether it be a Daisy or a Pansy or whatever derived class instance.  If I set
&lt;pre&gt;
Flower.prototype.myTask = flowerTask;
&lt;/pre&gt;
then on arrival, my character can call
&lt;pre&gt;
target["myTask"]();
&lt;/pre&gt;
and the flowerTask is the one that will be executed if the target is any Flower derivative.  Of course every potential target class has myTask defined on its prototype or on an ancestor prototype; I set a default myTask on Sprite.prototype to cover the undefined cases.</description>
		<content:encoded><![CDATA[<p>Dennis,</p>
<p>The advantage of saying</p>
<pre>
SomeClass.prototype.variable = value;
</pre>
<p>is that it&#8217;s completely dynamic &#8212; the variable does not have to have been declared as a property in SomeClass.as, and it can be set by any code outside the class &#8212; and it can be accessed as though it were a property of any instance of SomeClass or of any derived class &#8212; either by declaring the class dynamic, or by using the bracket notation:</p>
<pre>
someClassInstance["variable"]
</pre>
<p>A protected variable would have to have been declared in the class file, would have to be set on every instance that needs it, and cannot be accessed from unrelated code.</p>
<p>To be more specific about a use case, consider a specific function that a game character must execute whenever he arrives at any Flower, whether it be a Daisy or a Pansy or whatever derived class instance.  If I set</p>
<pre>
Flower.prototype.myTask = flowerTask;
</pre>
<p>then on arrival, my character can call</p>
<pre>
target["myTask"]();
</pre>
<p>and the flowerTask is the one that will be executed if the target is any Flower derivative.  Of course every potential target class has myTask defined on its prototype or on an ancestor prototype; I set a default myTask on Sprite.prototype to cover the undefined cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-119734</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Sun, 27 Apr 2008 22:32:22 +0000</pubDate>
		<guid isPermaLink="false">http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-119734</guid>
		<description>"it’s a great place to store variables that need to be available to every instance of a class and every instance of derived classes"

Eh, isn't the answer here "protected", or am I not following you correctly?</description>
		<content:encoded><![CDATA[<p>&#8220;it’s a great place to store variables that need to be available to every instance of a class and every instance of derived classes&#8221;</p>
<p>Eh, isn&#8217;t the answer here &#8220;protected&#8221;, or am I not following you correctly?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alan</title>
		<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-89218</link>
		<dc:creator>alan</dc:creator>
		<pubDate>Wed, 16 Jan 2008 05:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-89218</guid>
		<description>Actually I am using the prototype extensively in my current AS3 work; it's a great place to store variables that need to be available to every instance of a class and every instance of derived classes.  A static property wouldn't do because it's not inherited.

My question was really about using a function instead of a class as a constructor.  And that indeed does look rather useless.</description>
		<content:encoded><![CDATA[<p>Actually I am using the prototype extensively in my current AS3 work; it&#8217;s a great place to store variables that need to be available to every instance of a class and every instance of derived classes.  A static property wouldn&#8217;t do because it&#8217;s not inherited.</p>
<p>My question was really about using a function instead of a class as a constructor.  And that indeed does look rather useless.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joeflash</title>
		<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-88744</link>
		<dc:creator>Joeflash</dc:creator>
		<pubDate>Mon, 14 Jan 2008 07:27:37 +0000</pubDate>
		<guid isPermaLink="false">http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-88744</guid>
		<description>In AS1 &#38; AS2, the prototype chain was how classes were actually created, and the inheritance chain was merely a compiler-based syntax. AS3 is no longer a prototype-based language, so the inheritance chain trumps the prototype chain. However, in order to keep ties with the roots of the language (even though there is no direct compatibility between AS1/2 and AS3), the prototype property of a class may still be used. The only use case I can think of for using this legacy remnant of the language, though I've never actually tried it -- and like Keith I too am happy to see this aspect of the language "go away" -- is if you need to create dynamic pseudo-classes from a prototype-based level, in an application such as a Design Patterns simulator, or a UML application which can generate stub code, though there are far better ways to do this through AS3's new introspection API.</description>
		<content:encoded><![CDATA[<p>In AS1 &amp; AS2, the prototype chain was how classes were actually created, and the inheritance chain was merely a compiler-based syntax. AS3 is no longer a prototype-based language, so the inheritance chain trumps the prototype chain. However, in order to keep ties with the roots of the language (even though there is no direct compatibility between AS1/2 and AS3), the prototype property of a class may still be used. The only use case I can think of for using this legacy remnant of the language, though I&#8217;ve never actually tried it &#8212; and like Keith I too am happy to see this aspect of the language &#8220;go away&#8221; &#8212; is if you need to create dynamic pseudo-classes from a prototype-based level, in an application such as a Design Patterns simulator, or a UML application which can generate stub code, though there are far better ways to do this through AS3&#8217;s new introspection API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Peters</title>
		<link>http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-88674</link>
		<dc:creator>Keith Peters</dc:creator>
		<pubDate>Mon, 14 Jan 2008 00:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://nodename.com/blog/2008/01/13/advanced-users-may-choose/#comment-88674</guid>
		<description>I don't know if there is a particular use case. It's just how things are made up. That's how we did "classes" in AS1. I'm glad to leave it behinde, personally. :)</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know if there is a particular use case. It&#8217;s just how things are made up. That&#8217;s how we did &#8220;classes&#8221; in AS1. I&#8217;m glad to leave it behinde, personally. :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
