<?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>风雪之隅 &#187; var</title>
	<atom:link href="http://www.laruence.com/tag/var/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>IE下var的重要性的又一佐证</title>
		<link>http://www.laruence.com/2010/01/21/1254.html</link>
		<comments>http://www.laruence.com/2010/01/21/1254.html#comments</comments>
		<pubDate>Thu, 21 Jan 2010 04:43:07 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[var]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1254</guid>
		<description><![CDATA[ 一个朋友问了一个js问题, 一段看不出有任何问题的代码, 在ie下报错:"object doesn't support this property or method".
 <coolcode lang="javascript" linenum="off">
function foo(obj) {
   productTree = obj.toString();
   document.getElementById('productTree').innerHTML = productTree;
} 
</coolcode>
</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/01/21/1254.html"  title="Permanet Link to IE下var的重要性的又一佐证" >http://www.laruence.com/2010/01/21/1254.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
   一个朋友问了一个js问题, 一段看不出有任何问题的代码, 在ie下报错:&#8221;object doesn&#8217;t support this property or method&#8221;.</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function foo(obj) {
   productTree = obj.toString();
   document.getElementById('productTree').innerHTML = productTree;
}
</pre>
<p>    开始, 还以为错误是指obj的toString方法, 绕了半天弯路, 无果..</p>
<p>    后来,注意到变量名是productTree没有用var申明, 加上getElementById(&#8216;productTree&#8217;)说明有个id为productTree的元素, 并且我们知道在IE下可以直接通过id获取DOM元素的引用, so~</p>
<p>    所以啊, 局部变量一定要用var申明, 不仅仅是因为不用var会成全局变量, 更因为在IE下, 有可能会出现这种, 让人很莫名的错误&#8230;.
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/21</a>, rzhome writes: 在IE下就是这样的痛苦，不过加var来声明变量应该规范点。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/21</a>, yangliang writes: 难道window下的所有变量ie都认为是dom咯，该死的ie</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/22</a>, janpoem writes: 这是ie的老问题了，应该规范使用var声明变量。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/12/13</a>, mark35 writes: 据统计各种语言代码中中出现fuc..k词语频率是JS最高。因为IE系列的存在。呵呵。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=253"  rel="external nofollow"  class="url" >IE下var的重要性的又一佐证 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2010/01/21/1254.html [...]</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2011/04/25</a>, kgh writes: JavaScript 是一门灵活的语言，但往往越是灵活就越是容易出错！有些东西还是强制规范好些的！</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/07/11/108.html"  title="IE下的Javascript调试利器:Companion.js" >IE下的Javascript调试利器:Companion.js</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/04/12/1394.html"  title="IE下pre标签的InnerHTML问题" >IE下pre标签的InnerHTML问题</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/01/21/1254.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

