<?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>Blog de desenvolvimento da Milfont Consulting, Client e Server-side &#187; Prototype</title>
	<atom:link href="http://www.milfont.org/tech/category/frameworks/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.milfont.org/tech</link>
	<description>Blog da Comunidade Milfont Consulting, uma empresa especializada em desenvolvimento Web, principalmente Javascript, node.js e muito Javascript.</description>
	<lastBuildDate>Thu, 26 Jan 2012 11:30:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Encontro em Iguatu</title>
		<link>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/</link>
		<comments>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:19:34 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[cejug]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[palestras]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=365</guid>
		<description><![CDATA[O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no encontro das comunidades PHP e Java no dia 1/11/2008. Fernando Chucre iniciou o evento palestrando pelo CEPUG sobre PHP Orientado a objetos. Logo em seguida foi a vez do Jefferson [organizador do evento] palestrar sobre Debug no PHP. Pelo CEJUG o Silveira Neto [...]]]></description>
			<content:encoded><![CDATA[<p>O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no <a href="http://www.milfont.org/tech/2008/10/24/encontro-java-e-php-em-iguatu-ce/">encontro das comunidades PHP e Java</a> no dia 1/11/2008.</p>
<p><a href="http://horizontesdigitais.com/">Fernando Chucre</a> iniciou o evento palestrando pelo <a href="http://cepug.org/2008/11/evento-em-iguatu-foi-um-sucesso-agora-e-fortaleza/">CEPUG</a> sobre PHP Orientado a objetos. Logo em seguida foi a vez do <a href="http://jefferson.eti.br/">Jefferson</a> [organizador do evento] palestrar sobre Debug no PHP.<br />
Pelo <a href="http://www.cejug.org/display/cejug/Apresentando+o+CEJUG+e+o+poder+do+Java+e+Frameworks+AJAX+em+Iguatu+-+01.11.08">CEJUG</a> o <a href="http://silveiraneto.net/2008/11/03/1%c2%ba-encontro-cejugcepug-em-iguatu/">Silveira Neto</a> apresentou uma palestra sobre a comunidade e o poder do Java, seguido por mim sobre Frameworks Ajax focado em Java com utilização de DWR e ExtJS.</p>
<p>O detalhe mais importante foi constatar a maturidade de duas comunidades tão distintas que compartilharam o mesmo evento sem nenhum problema, egocentrismo ou picuinha. Eu já estou cansando de ir em eventos onde o pessoal só fala de outra tecnologia, como eventos de linguagem onde falam mal de Java o evento inteiro. Cada um apresentou sua palestra sem desmerecer nenhuma tecnologia ou ninguém.</p>
<h2>Material</h2>
<div id="__ss_719498" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Frameworks Ajax" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">Frameworks Ajax</a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View SlideShare <a style="text-decoration:underline;" title="View Frameworks Ajax on SlideShare" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/ajax">ajax</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/iguatu">iguatu</a>)</div>
</div>
<h2>Fotos</h2>
<p><a href="http://picasaweb.google.com.br/cmilfont/Iguatu1112008">Picasa do CMilfont</a><br />
<a href="http://www.flickr.com/photos/silveiraneto/sets/72157608607361149/">Flcikr do Silveira</a></p>
<p><img src="http://lh5.ggpht.com/_Mm7CP-3dJvI/SQ7tkg3kpLI/AAAAAAAAAvc/woXXELjYiJg/s400/IMG_2173.JPG" alt="iguatu" /></p>
<p><img src="http://farm4.static.flickr.com/3163/2997081263_b20482857b.jpg?v=0" alt="minha apresentacao" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Função Dollar do Prototype para capturar elementos HTML</title>
		<link>http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/</link>
		<comments>http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/#comments</comments>
		<pubDate>Sat, 13 Oct 2007 22:11:31 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Prototypejs]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/</guid>
		<description><![CDATA[Enquanto não preparo um material exclusivo sobre manpulação DOM da especificação W3C, gostaria de falar sobre o encapsulamento dessas operações que os Frameworks Javascript fazem. A funcionalidade principal de todos os Frameworks, é abstrair a complexidade da manipulação DOM, que não é tão complexa assim mas é chata para muitos. Como o DOM é o [...]]]></description>
			<content:encoded><![CDATA[<p>Enquanto não preparo um material exclusivo sobre manpulação <a href="http://www.w3.org/DOM/">DOM</a> da especificação W3C, gostaria de falar sobre o encapsulamento dessas operações que os <a href="http://www.milfont.org/tech/2007/10/11/frameworks-ajax/">Frameworks</a> Javascript fazem.</p>
<p>A funcionalidade principal de todos os Frameworks, é abstrair a complexidade da manipulação DOM, que não é tão complexa assim mas é chata para muitos. Como o DOM é o acesso aos elementos, e dependemos deles para montar a UI (User Interface) das aplicações, todos (Frameworks) tentam minimizar ou associar essa manipulação com a facilidade de linguagens UI que temos costume no desktop.</p>
<p>O <a href="http://www.extjs.com">Extjs</a> por exemplo, tem o objeto <a href="http://www.extjs.com/deploy/ext/docs/output/Ext.Element.html">Ext.Element</a> que representa um <a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-745549614">elemento DOM</a> e possui métodos amigáveis como: Ext.get(id), para capturar um elemento, Ext.get(&#8220;my-div&#8221;).setWidth(100) para setar uma largura de 100 pixels a um elemento capturado, entre outros métodos.</p>
<p>O <a href="http://brunotorres.net/">Bruno Torres</a> em seu projeto, <a href="http://www.obasicodaweb.com/sobre">O Básico da web</a>, escreveu um <a href="http://www.obasicodaweb.com/como-selecionar-elementos-html-via-javascriptdom">artigo básico</a> sobre captura de elementos HTML. Esse artigo me inspirou a falar sobre a função $ (Dollar) famosa no Framework <a href="http://www.prototypejs.org/">Prototype</a> pela simplicidade. Quem quiser aprender como se seleciona um elemento DOM, dê uma olhada no <a href="http://www.obasicodaweb.com/como-selecionar-elementos-html-via-javascriptdom">artigo</a>, lá está bem explicado e com uma didática legal.</p>
<p>A função <a href="http://www.prototypejs.org/api/utility/dollar">$ (Dollar)</a>, símbolo do uso do Prototype, representa um mecanismo &#8220;conveniente&#8221; de captura de um elemento, presenteado com métodos auxiliares para a manipulação do DOM em um lote de elementos.</p>
<p>Para capturar o elemento DOM, você precisa usar a sintaxe:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id_elemento&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A partir daí podemos selecionar ou alterar suas propriedades como:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// exibe o conteúdo</span></pre></div></div>

<p>Enquanto no Prototype, a função $ providencia um acesso mais limpo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id_elemento&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Essa função é amada por todos os desenvolvedores javascript, a construção dela é absolutamente simples:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> $<span style="color: #009900;">&#40;</span>els<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> els.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> els<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> element <span style="color: #339933;">==</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O código da função acrescenta os elementos passados como parâmetros (caso queira capturar vários, apenas separe por vírgula) em uma propriedade array na função. Caso o parâmetro seja uma String, um elemento é capturado pela forma tradicional usando essa String (que deve ser referência a um ID) e acrescentado no array, a cláusula return devolve o escopo da própria função.</p>
<p>A função $ é enriquecida com funçõse que manpulam esse conjunto de elementos. A lógica é que ao retornar esse elemento(s), uma função seja acionada e manipule esse elemento (ou conjunto deles). Essas funções podem ser adicionadas via prototype (propriedade herdada da Global que representa o escopo interno de todos os objetos):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>    
	each<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>len<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Assim, ao selecionar vários elementos, podemos aplicar essas funções diretamente. Outras funções podem ser adicionadas usando o prototype, criando um ecosistema elementar para manipulação desses elementos.</p>
<p>Veja como a aplicação dessa função reduz o código necessário para acionarmos um elemento diretamente e aplicarmos uma instrução que se feita por DOM, levaria várias linhas:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'botao'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> 
	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 	
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'teste'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'teste'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Nos próximos posts, destilaremos vários frameworks e como cada um faz sua manipulação.</p>
<h3 id="update-fev-2008">[UPDATE 10-02-2008]</h3>
<p>Para exemplificar melhor como trabalha o Framework Prototype, Devido aos <a href="http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/#comment-282">comentários</a> do <a href="http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/#comment-284">Edu</a>, ficou faltando código para compreender como a função &#8220;$&#8221; está disponível no código.</p>
<p>Nas versões antigas do framework, eles faziam assim:</p>
<ol>
<li>Cria-se uma função privada no contexto referenciada por _$;</li>
<li>Retorna uma instãncia dessa função _$ referenciada a $;</li>
</ol>
<p>Como fica isso em código:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">// função privada com o código que vimos nesse post</span>
  <span style="color: #003366; font-weight: bold;">function</span> _$<span style="color: #009900;">&#40;</span>els<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>els.<span style="color: #660066;">length</span><span style="color: #339933;">;&gt;</span>
      <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> els<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> element <span style="color: #339933;">==</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>els.<span style="color: #660066;">length</span><span style="color: #339933;">;&gt;</span></pre></div></div>

<p>Cria a função global &#8220;$&#8221; com referência a uma instância da função privada &#8220;_$&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $ <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> _$<span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O código completo ficaria assim:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">function</span> _$<span style="color: #009900;">&#40;</span>els<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>els.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> els<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> element <span style="color: #339933;">==</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  _$.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    each<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    setStyle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>prop<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        el.<span style="color: #660066;">style</span><span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    addClass<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>className<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        el.<span style="color: #660066;">className</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>className<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    css<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> prop <span style="color: #000066; font-weight: bold;">in</span> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          that.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span>prop<span style="color: #339933;">,</span> o<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  $ <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> _$<span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Observe que hoje ficou bem mais rebuscado no código das últimas versões, mas o conceito é o mesmo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/10/13/funcao-dollar-do-prototype-para-capturar-elementos-html/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

