<?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>Live in code &#187; javascript</title>
	<atom:link href="http://www.agatezone.cn/code/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.agatezone.cn/code</link>
	<description>agate&#039;s tech blog</description>
	<lastBuildDate>Tue, 20 Jul 2010 05:35:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Chart Tools</title>
		<link>http://www.agatezone.cn/code/archives/583</link>
		<comments>http://www.agatezone.cn/code/archives/583#comments</comments>
		<pubDate>Sat, 13 Feb 2010 05:00:35 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=583</guid>
		<description><![CDATA[今天看到 google 出了一组很酷的图形 API

地址: http://code.google.com/apis/charttools/
目前提供:
1. Image charts - using a simple URL request to a Google chart server
2. Interactive charts - using a Google developed JavaScript library
具体的就是:
1 -- [图片型图标] 只是一个图片而已
2 -- [可视化图标] 是一个 javascript 实现的可视化图形组件, 提供动态显示和鼠标事件
具体可以到: http://code.google.com/apis/charttools/docs/choosing.html 看看二者的区别
]]></description>
			<content:encoded><![CDATA[<p>今天看到 google 出了一组很酷的图形 API</p>
<p><img src="http://chart.apis.google.com/chart?cht=bhs&#038;chs=75x50&#038;chd=t:10,50,60,80,40|50,60,100,40,20&#038;chco=4d89f9,c6d9fd&#038;chbh=20&#038;chds=0,160&#038;chbh=a" title="Bar Charts" /><img src="http://chart.apis.google.com/chart?chs=75x75&#038;cht=ls&#038;chd=t0:0,17,7,6|0,30,27,54|0,45,47,46|0,63,59,60|-1,40,35,-1|-1,5,70,-1|-1,-1,80,-1&#038;chm=F,0000FF,0,1:2,10|H,0000FF,0,1:2,1:10|H,0000FF,3,1:2,1:10|H,0000FF,4,1:2,1:10|o,FF0000,5,,5|o,FF0000,6,,5" title="Box Charts" /><img src="http://chart.apis.google.com/chart?chs=75x50&#038;cht=lc&#038;chd=t0:-1,5,10,7,12,-1|-1,25,45,47,24,-1|-1,40,30,27,39,-1|-1,55,63,59,80,-1&#038;chm=F,0000FF,0,,10" title="Candlestick Charts" /><img src="http://chart.apis.google.com/chart?cht=bvs&#038;chbh=5,2&#038;chm=D,0033FF,2,0,5,1&#038;chbh=20&#038;chs=75x50&#038;chd=s2:1XQbnf4,EWoQMUB,9halxp9&#038;chco=4D89F9,C6D9FD&#038;chbh=a" title="Compound Charts" /><img src="http://chart.apis.google.com/chart?chst=d_bubble_icon_text_small&#038;chld=ski|bb|Wheeee!|FFFFFF|000000" title="Dynamic Icons" /><img src="http://chart.apis.google.com/chart?cht=tx&#038;chl=x%20=%20%5Cfrac%7B-b%20%5Cpm%20%5Csqrt%20%7Bb%5E2-4ac%7D%7D%7B2a%7D" title="Formulas" /><img src="http://chart.apis.google.com/chart?chs=75x50&#038;cht=gom&#038;chd=t:70&#038;chco=FF0000,FF8040,FFFF00,00FF00,00FFFF,0000FF,800080" title="Google-O-Meter Charts" /><img src="http://chart.apis.google.com/chart?cht=lxy&#038;chs=75x50&#038;chd=t:10,20,40,80,90,95,99|20,30,40,50,60,70,80|-1|5,10,22,35,85&#038;chco=3072F3,ff0000,00aaaa&#038;chm=s,FF0000,0,-1,2|s,0000ff,1,-1,2|s,00aa00,2,-1,2" title="Line Charts" /><img src="http://chart.apis.google.com/chart?cht=t&#038;chs=150x75&#038;chd=t:0,100,50,32,60,40,43,12,14,54,98,17,70,76,18,29&#038;chco=FFFFFF,FF0000,FFFF00,00FF00&#038;chld=DZEGMGAOBWNGCFKECGCVSNDJTZGHMZZM&#038;chtm=africa&#038;chf=bg,s,EAF7FE" title="Map Charts" /><img src="http://chart.apis.google.com/chart?cht=p3&#038;chd=s:Uf9a&#038;chs=75x50" title="Pie Charts" /><img src="http://chart.apis.google.com/chart?chs=50x50&#038;cht=qr&#038;chl=Hello+world&#038;chld=L|1&#038;choe=UTF-8" title="QR Codes" /><img src="http://chart.apis.google.com/chart?cht=rs&#038;chs=75x75&#038;chd=t:77,66,15,0,31,48,100,77|20,36,100,2,0,100&#038;chco=FF0000,FF9900&#038;chls=2.0,4.0,0.0|2.0,4.0,0.0&#038;chxt=x&#038;chxl=0:|0|45|90|135|180|225|270|315&#038;chxr=0,0.0,360.0&#038;chg=25.0,25.0,2.0,2.0&#038;chm=B,FF000080,0,1.0,5.0|B,FF990080,1,1.0,5.0&#038;chxs=0,000000,4,0" title="Radar Charts" /><img src="http://chart.apis.google.com/chart?cht=s&#038;chd=t:12,87,75,41,23,96,68,71,34,9|98,60,27,34,56,79,58,74,18,76|42,11,33,40,22,45,30,45,32,27&#038;chs=75x50&#038;chco=FF0000" title="Scatter Charts" /><img src="http://chart.apis.google.com/chart?cht=v&#038;chs=75x50&#038;chd=t:100,100,0,50" title="Venn Charts" /></p>
<p>地址: http://code.google.com/apis/charttools/</p>
<p>目前提供:<br />
1. Image charts - using a simple URL request to a Google chart server<br />
2. Interactive charts - using a Google developed JavaScript library<br />
具体的就是:<br />
1 -- [图片型图标] 只是一个图片而已<br />
2 -- [可视化图标] 是一个 javascript 实现的可视化图形组件, 提供动态显示和鼠标事件</p>
<p>具体可以到: http://code.google.com/apis/charttools/docs/choosing.html 看看二者的区别</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/583/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery &amp; Prototype 特点对比</title>
		<link>http://www.agatezone.cn/code/archives/519</link>
		<comments>http://www.agatezone.cn/code/archives/519#comments</comments>
		<pubDate>Fri, 06 Nov 2009 04:14:31 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=519</guid>
		<description><![CDATA[
这个是搜来的一个 PPT, 介绍的不错.
从个人角度看来就是: 建立 OO 机制选用 Protytpe, 操作 DOM 用 jQuery.
(P.S. 说到 javascript OO. 我宁可自己写 OO 框架, 多轻量!)
]]></description>
			<content:encoded><![CDATA[<p><object style="margin:0px" 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.slidesharecdn.com/swf/ssplayer2.swf?doc=prototype-jquery-going-from-one-to-the-other-1193346036472971-5&amp;stripped_title=prototype-jquery-going-from-one-to-the-other" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=prototype-jquery-going-from-one-to-the-other-1193346036472971-5&amp;stripped_title=prototype-jquery-going-from-one-to-the-other" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>这个是搜来的一个 PPT, 介绍的不错.<br />
从个人角度看来就是: 建立 OO 机制选用 Protytpe, 操作 DOM 用 jQuery.<br />
(P.S. 说到 javascript OO. 我宁可自己写 OO 框架, 多轻量!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/519/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DOM 元素的 innerHTML 只读问题</title>
		<link>http://www.agatezone.cn/code/archives/512</link>
		<comments>http://www.agatezone.cn/code/archives/512#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:26:14 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=512</guid>
		<description><![CDATA[今天在 chrome 下发现一个 innerHTML 调用的时候抛出 DOM Error 问题. 经过一番折腾之后发现是 webkit 对于某些 DOM 元素的 innerHTML 属性有只读保护机制. 但是 firefox 上面确没有这类问题.
经过 google 的一番查证之后, 发现这个不仅仅是 webkit 类浏览器的问题. 其实 ie 也是. msdn 文档如是说:
innerHTML:
The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. The [...]]]></description>
			<content:encoded><![CDATA[<p>今天在 chrome 下发现一个 innerHTML 调用的时候抛出 DOM Error 问题. 经过一番折腾之后发现是 webkit 对于某些 DOM 元素的 innerHTML 属性有只读保护机制. 但是 firefox 上面确没有这类问题.</p>
<p>经过 google 的一番查证之后, 发现这个不仅仅是 webkit 类浏览器的问题. 其实 ie 也是. msdn 文档如是说:</p>
<blockquote><p>innerHTML:<br />
The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.</p></blockquote>
<p>说白了就是这几个特殊的 DOM 元素的 innerHTML 属性是只读的.</p>
<p>当当当当~ 经验值 +320.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/512/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>javascript: call 和 apply 方法</title>
		<link>http://www.agatezone.cn/code/archives/451</link>
		<comments>http://www.agatezone.cn/code/archives/451#comments</comments>
		<pubDate>Thu, 16 Jul 2009 10:05:08 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=451</guid>
		<description><![CDATA[call写法为: fun.call(thisArg[, arg1[, arg2[, ...]]])
apply写法为: fun.apply(thisArg, [argsArray])
其中 call 和 apply 的第一个参数是一致的, 其实就是设定 this 对象. 两个方法的区别在于 call 的参数是分开传的, apply 是拼成数组传的(很适合直接传递 arguments)

// 以下两个实现效果一致.

jq.click(function (e) {
  fun.call(this, e);
});

jq.click(function () {
  fun.apply(this, arguments);
});

]]></description>
			<content:encoded><![CDATA[<p>call写法为: fun.call(thisArg[, arg1[, arg2[, ...]]])<br />
apply写法为: fun.apply(thisArg, [argsArray])</p>
<p>其中 call 和 apply 的第一个参数是一致的, 其实就是设定 this 对象. 两个方法的区别在于 call 的参数是分开传的, apply 是拼成数组传的(很适合直接传递 arguments)</p>
<pre class="brush: jscript;">
// 以下两个实现效果一致.

jq.click(function (e) {
  fun.call(this, e);
});

jq.click(function () {
  fun.apply(this, arguments);
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/451/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript: 方法名别和变量名重复</title>
		<link>http://www.agatezone.cn/code/archives/419</link>
		<comments>http://www.agatezone.cn/code/archives/419#comments</comments>
		<pubDate>Tue, 02 Jun 2009 02:42:56 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=419</guid>
		<description><![CDATA[今天在写程序的时候发现我明明写了一个名为 isOpen 的方法, 可是在调用的时候 firebug 就死活提示没有该方法. 甚至以为有缓存... 百思不得其解. 还好 leon 发现我在当前这个对象中有一个同名的变量名... 这个太恶心了!

function isOpen () {
  return this.isOpen; // 这个是错误的原因: 两个 isOpen...
}

function isOpen () {
  return this.opened; // 这样就没事了!
}

]]></description>
			<content:encoded><![CDATA[<p>今天在写程序的时候发现我明明写了一个名为 isOpen 的方法, 可是在调用的时候 firebug 就死活提示没有该方法. 甚至以为有缓存... 百思不得其解. 还好 leon 发现我在当前这个对象中有一个同名的变量名... 这个太恶心了!</p>
<pre class="brush: jscript;">
function isOpen () {
  return this.isOpen; // 这个是错误的原因: 两个 isOpen...
}

function isOpen () {
  return this.opened; // 这样就没事了!
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/419/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript: window.location</title>
		<link>http://www.agatezone.cn/code/archives/414</link>
		<comments>http://www.agatezone.cn/code/archives/414#comments</comments>
		<pubDate>Wed, 20 May 2009 03:27:01 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=414</guid>
		<description><![CDATA[在 javascript 中常需要获取或者修改当前页面的地址
可以使用 window.location 这个对象

window.location = {
  // attributes
  hash:     //Sets or returns the URL from the hash sign (#)
  host:     //Sets or returns the hostname and port number of the current URL
  hostname: //Sets or returns the hostname of the current URL
 [...]]]></description>
			<content:encoded><![CDATA[<p>在 javascript 中常需要获取或者修改当前页面的地址<br />
可以使用 window.location 这个对象</p>
<pre class="brush: jscript;">
window.location = {
  // attributes
  hash:     //Sets or returns the URL from the hash sign (#)
  host:     //Sets or returns the hostname and port number of the current URL
  hostname: //Sets or returns the hostname of the current URL
  href:     //Sets or returns the entire URL
  pathname: //Sets or returns the path of the current URL
  port:     //Sets or returns the port number of the current URL
  protocol: //Sets or returns the protocol of the current URL
  search:   //Sets or returns the URL from the question mark (?)

  // methods
  assign():  //Loads a new document
  reload():  //Reloads the current document
  replace(): //Replaces the current document with a new one
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/414/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>注意 jQuery 中的多重事件绑定</title>
		<link>http://www.agatezone.cn/code/archives/363</link>
		<comments>http://www.agatezone.cn/code/archives/363#comments</comments>
		<pubDate>Sat, 10 Jan 2009 15:20:17 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=363</guid>
		<description><![CDATA[一直以来都是简单地使用 w3c 的 dom 模式的 javascript 编程模式. 直到最近才开始使用 jquery. 也是由此发现其的强大! 在这里感叹一下: "这东西他妈太好了! 不过开始有依赖性了!!!"
言归正传, 在开发的过程中发现了一个小特点, 需要注意一下: 就是 jquery 的事件绑定机制是累加式的, 说白了就是可以重复注册事件的处理方式, 并在事件触发的时候统统执行. 明显, 这个是有好处的. 我们担心不必在大型前端的 javascript 脚本中覆盖我们原先的事件注册. 但是常常我们也遇到一个事件多次被执行的问题(其实就是某些情况下我们的时间注册了多次.)
在 dom scripting 中我们常常这么注册事件:
HTML:
&#60;p id="clickable"&#62;click me!&#60;p&#62;
JAVASCRIPT:
document.getElementById("clickable").onclick = function () { alert(1); };
document.getElementById("clickable").onclick = function () { alert(2); };
测试点击这个段落, 只会有一次 alert 并且内容为 2 (即最后一次注册的);
但是在 jquery 中我们这样:
HTML:
&#60;p id="clickable"&#62;click me!&#60;p&#62;
JAVASCRIPT:
$('#clickable').onclick(function () { alert(1); [...]]]></description>
			<content:encoded><![CDATA[<p>一直以来都是简单地使用 w3c 的 dom 模式的 javascript 编程模式. 直到最近才开始使用 jquery. 也是由此发现其的强大! 在这里感叹一下: "这东西他妈太好了! 不过开始有依赖性了!!!"</p>
<p>言归正传, 在开发的过程中发现了一个小特点, 需要注意一下: 就是 jquery 的事件绑定机制是累加式的, 说白了就是可以重复注册事件的处理方式, 并在事件触发的时候统统执行. 明显, 这个是有好处的. 我们担心不必在大型前端的 javascript 脚本中覆盖我们原先的事件注册. 但是常常我们也遇到一个事件多次被执行的问题(其实就是某些情况下我们的时间注册了多次.)</p>
<p>在 dom scripting 中我们常常这么注册事件:<br />
HTML:<br />
<code>&lt;p id="clickable"&gt;click me!&lt;p&gt;</code><br />
JAVASCRIPT:<br />
<code>document.getElementById("clickable").onclick = function () { alert(1); };<br />
document.getElementById("clickable").onclick = function () { alert(2); };</code><br />
测试点击这个段落, 只会有一次 alert 并且内容为 2 (即最后一次注册的);</p>
<p>但是在 jquery 中我们这样:<br />
HTML:<br />
<code>&lt;p id="clickable"&gt;click me!&lt;p&gt;</code><br />
JAVASCRIPT:<br />
<code>$('#clickable').onclick(function () { alert(1); });<br />
$('#clickable').onclick(function () { alert(2); });</code><br />
测试点击这个段落, 两次 alert 都会出现.</p>
<p>所以如果需要只有一个事件绑定的话可以使用 jquery 自带的 unbind 方法来解除指定时间的所有绑定执行代码. 例如:<br />
<code>$('#clickable').unbind('onclick');</code><br />
这样就解除了 onclick 的所有绑定方法.<br />
(ps. jquery 中 jqObj.event(function) 相当于 jqObj.bind('event', function))</p>
<p>这个问题在开发中需要注意!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/363/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript 中 hash 或者 object 结构的迭代</title>
		<link>http://www.agatezone.cn/code/archives/342</link>
		<comments>http://www.agatezone.cn/code/archives/342#comments</comments>
		<pubDate>Thu, 25 Dec 2008 08:56:46 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=342</guid>
		<description><![CDATA[javascript 中的 objcet 很特别, 说白了还是一个 hash, 今天突然需要便利所有 hash 中的 keys. 所以就查阅了一下其迭代的方法:

for (var key in hash) {
  // key is just what you need
  // you can get the value by hash['key']
}

更多 javascript 的 hash 实现方式可以参阅 Hash Tables in Javascript
]]></description>
			<content:encoded><![CDATA[<p>javascript 中的 objcet 很特别, 说白了还是一个 hash, 今天突然需要便利所有 hash 中的 keys. 所以就查阅了一下其迭代的方法:</p>
<pre class="brush: jscript;">
for (var key in hash) {
  // key is just what you need
  // you can get the value by hash['key']
}
</pre>
<p>更多 javascript 的 hash 实现方式可以参阅 <a href="http://www.mojavelinux.com/articles/javascript_hashes.html" onclick="pageTracker._trackPageview('/outgoing/www.mojavelinux.com/articles/javascript_hashes.html?referer=');">Hash Tables in Javascript</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/342/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE &amp; Firefox javascript 语法区别记录</title>
		<link>http://www.agatezone.cn/code/archives/340</link>
		<comments>http://www.agatezone.cn/code/archives/340#comments</comments>
		<pubDate>Wed, 24 Dec 2008 23:59:57 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=340</guid>
		<description><![CDATA[随着 IE 不断升级, 其也越来越规范化. 渐渐地和大多数浏览器也越来越表现一致化了~ 但是还是有一些不同. 这里就记录一下我所碰到的 IE 和 Firefox 解析 javascript 时候的语法区别:
1. 结尾逗号问题
[ 1, 2, 3 ]
{ a:1, b:2, c:3 }
一个 array 一个 hash 都是我们在 javascript 中常见的数据结构. 但是在 Firefox 中是可以在最后一个元素后面继续加入逗号的, 例如
[ 1, 2, 3, ]
{ a:1, b:2, c:3, }
但是 IE 就比较严格, 不可这么写, 必须去掉最后一个空格.
( PS 这点上我觉得 IE 比较规范... )
2. for 关键字
这里不是说循环, 而是说 hash 的赋值方式. 当我们的一个 [...]]]></description>
			<content:encoded><![CDATA[<p>随着 IE 不断升级, 其也越来越规范化. 渐渐地和大多数浏览器也越来越表现一致化了~ 但是还是有一些不同. 这里就记录一下我所碰到的 IE 和 Firefox 解析 javascript 时候的语法区别:</p>
<p><strong>1. 结尾逗号问题</strong><br />
[ 1, 2, 3 ]<br />
{ a:1, b:2, c:3 }<br />
一个 array 一个 hash 都是我们在 javascript 中常见的数据结构. 但是在 Firefox 中是可以在最后一个元素后面继续加入逗号的, 例如<br />
[ 1, 2, 3, ]<br />
{ a:1, b:2, c:3, }<br />
但是 IE 就比较严格, 不可这么写, 必须去掉最后一个空格.<br />
( PS 这点上我觉得 IE 比较规范... )</p>
<p><strong>2. for 关键字</strong><br />
这里不是说循环, 而是说 hash 的赋值方式. 当我们的一个 hash 有一个 key 名字叫做 for 的话, 在 Firefox 中我们可以这么写:<br />
hash.for = xxx  OR xxx = hash.for OR hash['for'] = xxx OR xxx = hash['for']<br />
但是很可惜, IE 中这样就会出错! 有可能其把 for 当作是关键字了或者什么其他特性( 不清楚 ), 总之 IE 中只能写成:<br />
hash['for'] = xxx OR xxx = hash['for']</p>
<p><strong>3. debugger 关键字</strong><br />
同 2 关键字. 一样的, debugger 在 ie 中也是一个关键字. 具体原因不知, 可能是俺装了 iedebugger 导致的. 总之最好改成其他名字, 或者使用 ['debugger']</p>
<p>[ updating ]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/340/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript 数组使用备忘</title>
		<link>http://www.agatezone.cn/code/archives/334</link>
		<comments>http://www.agatezone.cn/code/archives/334#comments</comments>
		<pubDate>Tue, 23 Dec 2008 08:00:52 +0000</pubDate>
		<dc:creator>agate</dc:creator>
				<category><![CDATA[程序编码]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.agatezone.cn/code/?p=334</guid>
		<description><![CDATA[在 javascript 中使用数组(哈希表)有很多小技巧(因为其是动态语言的缘故, 要比 java 灵活很多), 虽然基础了点, 但是还是想记录下来以备日后查阅:
基本特性
javascript 的数组不需要事先定义长度用时只要定义好数组的类型即可直接使用. 例如

var arr = []; // arr = new Array();
arr[1] = 111; // arr = [,1];
// 当然, hash 也是如此 hash = {}; 一样可以!

常用方法
push &#038; pop
作为数组实现栈数据结构的方法组合. push 把给定参数加载数组最后, pop 则对应取出数组的最后一个元素.(改变数组本身)
push &#038; shift
最为数组实现队数据结构的方法组合. shift 取出数组的第一个元素.(改变数组本身)
unshift
插入给定参数到数组之前. 比如 [2,3].unshift(0,1) => [0,1,2,3]
join
就是和 ruby 里头的 join 一样, 使用给定参数连接每个数组元素(方便处理最后一个连接, 而且效率很快). 例如

['CCTV', 'SMG', 'MTV'].join(', ') [...]]]></description>
			<content:encoded><![CDATA[<p>在 javascript 中使用数组(哈希表)有很多小技巧(因为其是动态语言的缘故, 要比 java 灵活很多), 虽然基础了点, 但是还是想记录下来以备日后查阅:</p>
<p><b>基本特性</b><br />
javascript 的数组不需要事先定义长度用时只要定义好数组的类型即可直接使用. 例如</p>
<pre class="brush: jscript;">
var arr = []; // arr = new Array();
arr[1] = 111; // arr = [,1];
// 当然, hash 也是如此 hash = {}; 一样可以!
</pre>
<p><b>常用方法</b><br />
<em>push &#038; pop</em><br />
作为数组实现栈数据结构的方法组合. push 把给定参数加载数组最后, pop 则对应取出数组的最后一个元素.(改变数组本身)</p>
<p><em>push &#038; shift</em><br />
最为数组实现队数据结构的方法组合. shift 取出数组的第一个元素.(改变数组本身)</p>
<p><em>unshift</em><br />
插入给定参数到数组之前. 比如 [2,3].unshift(0,1) => [0,1,2,3]</p>
<p><em>join</em><br />
就是和 ruby 里头的 join 一样, 使用给定参数连接每个数组元素(方便处理最后一个连接, 而且效率很快). 例如</p>
<pre class="brush: jscript;">
['CCTV', 'SMG', 'MTV'].join(', ') =&gt; 'CCTV, SMG, MTV'
</pre>
<p><em>sort &#038; reverse</em><br />
对应的两种排序方式, sort 为从小到达, reverse 为从大到小.</p>
<p><em>slice &#038; splice</em><br />
对应的两种数组截取方式. slice 只是截取出数组的某个区间段并输出(其不改变数组本身), splice 截取了某个区间段并替换成给定参数(没有给定参数就等于直接删除这个区间, 当然会改变数组本身). 例如</p>
<pre class="brush: jscript;">
arr      = [1,2,3,4,5]
arr_temp = arr.slice(2,4) // arr_temp = [3,4] &amp; arr = [1,2,3,4,5]
arr.splice(2,4,0) // arr = [1,2,0]
// 注意了 slice(m,n) 是取出 [m,n)
// splice(m,n,...) 是替换 [m,n]
</pre>
<p><b>总结</b><br />
其实呢~ javascript 是一个很奇特的脚本语言, 其中所有的东西都是变量/hash/数组, 而且只要声明了类型就可以直接使用, 不用担心什么越界之类的.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agatezone.cn/code/archives/334/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
