<?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>Tin&#039;s Blog &#187; Prototype</title>
	<atom:link href="http://www.diamondtin.com/tag/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.diamondtin.com</link>
	<description>you are coming a long way...</description>
	<lastBuildDate>Wed, 11 Aug 2010 09:43:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Firefox3 beta2带来的getElementsByClassName问题</title>
		<link>http://www.diamondtin.com/2008/firefox3-beta2%e5%b8%a6%e6%9d%a5%e7%9a%84getelementsbyclassname%e9%97%ae%e9%a2%98/</link>
		<comments>http://www.diamondtin.com/2008/firefox3-beta2%e5%b8%a6%e6%9d%a5%e7%9a%84getelementsbyclassname%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 07:19:25 +0000</pubDate>
		<dc:creator>tin</dc:creator>
				<category><![CDATA[Tech.技术]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://blog.agileito.com/tin/?p=5</guid>
		<description><![CDATA[Firefox3解决了一些内存泄露问题，或者说主要的是解决了一些长时间运行以后的内存占用问题。由于使用mac的习惯是休眠不关机，所还是在正式版出来之前选择了升级到firefox beta2。 那么作为开... ]]></description>
			<content:encoded><![CDATA[<p>Firefox3解决了一些内存泄露问题，或者说主要的是解决了一些长时间运行以后的内存占用问题。由于使用mac的习惯是休眠不关机，所还是在正式版出来之前选择了升级到firefox beta2。<br />
那么作为开发人员肯定遇到firebug不能用的问题，还好，我们可以用firebug的beta版本来解决这个问题，当然这个firebug还是会出现莫名其妙的问题，无所谓啦，不久就会发布正式版本了。<br />
这些都是废话，问题集中在firefox beta2提供了原生的getElementsByClassName方法，而我们大家都很愿意使用的prototype库正巧也给Element封装过getElementsByClassName方法，看起来两者的作用是一样的，但是不巧……其实两者还是有很大差别的，所以造成了如果你的项目正巧用了getElementsByClassName方法，而后你又用习惯的prototype方式便利了它……那么你的程序就不能在Firefox3 beta2工作了……<br />
我们以前的习惯就是不用考虑新浏览器的javascript兼容行问题，只需要考虑向后兼容，但是这次问题还是出现了变化。<br />
其实原因是简单的：<br />
1、Firefox3实现的原生getElementsByClassName方法返回的不是javascript数组（Array），而是html element collection，这个东西可以用标准的方式遍历，但是却与Array没有共同的prototype（这个指javascript里面的原型继承的prototype）。所以，很不幸，如果你用了Prototype库的那个返回Array的方法写程序，然后使用了Array增强方法里面的first()等方法或者Emmerable里面的each()等方法，那么程序一定会出错。此时你可以$A一下这个html element collection，但是这不是好方法。因为其实Prototype在1.6以后就不推荐使用getElementsByClassName方法了。<br />
2、那么解决的方法就是使用select方法代替原来的getElementsByClassName方法，不过记得要给参数的前面加个&#8221;.&#8221;。比如oneElement.getElementsByClassName(&#8216;someClass&#8217;)应该修改为oneElement.select(&#8216;.someClass&#8217;)。而其实select方法由于接受css selector语法，可以实现更强大的选择操作。</p>
<p>嗯，非常废话。<br />
那么简单的说：如果你在Firefox3里面发现你的基于Prototype库的js程序的getElementsByClassName以后出现了method null的错误，那么你需要用select方法代替它。且考虑到长时间的不兼容状态，最好完全消除你的程序中的getElementsByClassName同名方法调用，不关你用什么js库。</p>]]></content:encoded>
			<wfw:commentRss>http://www.diamondtin.com/2008/firefox3-beta2%e5%b8%a6%e6%9d%a5%e7%9a%84getelementsbyclassname%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
