<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JavaScript类型检测小结（上）</title>
	<atom:link href="http://lifesinger.org/blog/2009/02/javascript-type-check-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/</link>
	<description>关注用户体验、前端开发，记录生活点滴、岁月足迹。</description>
	<lastBuildDate>Sat, 13 Mar 2010 12:20:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: magiclx</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-2537</link>
		<dc:creator>magiclx</dc:creator>
		<pubDate>Wed, 09 Sep 2009 13:08:16 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-2537</guid>
		<description>function isArray(v) {
    return Object.prototype.toString.call(v) === &quot;[object Array]&quot; ? 1 : v.callee &#124;&#124; (typeof v.item != &quot;undefined&quot; &amp;&amp; !v.nodeType &amp;&amp; !v.alert) ? 2 : 0;
};
Array,HtmlCollection,arguments</description>
		<content:encoded><![CDATA[<p>function isArray(v) {<br />
    return Object.prototype.toString.call(v) === &#8220;[object Array]&#8221; ? 1 : v.callee || (typeof v.item != &#8220;undefined&#8221; &amp;&amp; !v.nodeType &amp;&amp; !v.alert) ? 2 : 0;<br />
};<br />
Array,HtmlCollection,arguments</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keakon</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-591</link>
		<dc:creator>keakon</dc:creator>
		<pubDate>Thu, 30 Apr 2009 07:00:49 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-591</guid>
		<description>其实整型字面量需要有个空格：

alert(1 .constructor);
或
alert(1
.constructor);

1.constructor实际上是1.0constructor，当然就出错了
而1..constructor实际上是1.0.constructor，这个也是不会出错的，只不过已经不是整型了。
当然，JavaScript里不分整型和浮点。</description>
		<content:encoded><![CDATA[<p>其实整型字面量需要有个空格：</p>
<p>alert(1 .constructor);<br />
或<br />
alert(1<br />
.constructor);</p>
<p>1.constructor实际上是1.0constructor，当然就出错了<br />
而1..constructor实际上是1.0.constructor，这个也是不会出错的，只不过已经不是整型了。<br />
当然，JavaScript里不分整型和浮点。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fdream</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-585</link>
		<dc:creator>Fdream</dc:creator>
		<pubDate>Tue, 10 Feb 2009 11:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-585</guid>
		<description>YUI也用的鸭子检测：

&lt;code&gt;isArray: function(o) {
    if (o) {
       return L.isNumber(o.length) &amp;&amp; L.isFunction(o.splice);
    }
    return false;
},
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>YUI也用的鸭子检测：</p>
<p><code>isArray: function(o) {<br />
    if (o) {<br />
       return L.isNumber(o.length) &amp;&amp; L.isFunction(o.splice);<br />
    }<br />
    return false;<br />
},<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lifesinger</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-586</link>
		<dc:creator>lifesinger</dc:creator>
		<pubDate>Sun, 08 Feb 2009 10:21:20 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-586</guid>
		<description>&lt;p&gt;还有一种写法是：&lt;code&gt;alert(1..constructor)&lt;/code&gt;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>还有一种写法是：<code>alert(1..constructor)</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: robbenmu</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-587</link>
		<dc:creator>robbenmu</dc:creator>
		<pubDate>Sat, 07 Feb 2009 13:32:56 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-587</guid>
		<description>alert(1[&#039;constructor&#039;]);
alert(1.constructor); // 肯定报错,&#039;.&#039;在这里小数点</description>
		<content:encoded><![CDATA[<p>alert(1['constructor']);<br />
alert(1.constructor); // 肯定报错,&#8217;.'在这里小数点</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lifesinger</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-588</link>
		<dc:creator>lifesinger</dc:creator>
		<pubDate>Thu, 05 Feb 2009 16:21:51 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-588</guid>
		<description>&lt;p&gt;公布问题1的答案：&lt;/p&gt;

&lt;pre&gt;
window.frames[window.frames.length - 1] == iframe.contentWindow;
&lt;/pre&gt;

因此文中的代码可以稍微简化为：
&lt;pre&gt;
var iframe = document.createElement(&#039;iframe&#039;);
document.body.appendChild(iframe);
var xArray = iframe.contentWindow.Array;
var arr = new xArray(1, 2, 3); // [1,2,3]

alert(arr.constructor === Array); // false
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>公布问题1的答案：</p>
<pre>
window.frames[window.frames.length - 1] == iframe.contentWindow;
</pre>
<p>因此文中的代码可以稍微简化为：</p>
<pre>
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var xArray = iframe.contentWindow.Array;
var arr = new xArray(1, 2, 3); // [1,2,3]

alert(arr.constructor === Array); // false
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: stainless</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-589</link>
		<dc:creator>stainless</dc:creator>
		<pubDate>Thu, 05 Feb 2009 10:20:46 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-589</guid>
		<description>1楼说得对

Duck typing就是用来关心对象的行为，而不是它是什么类型的。一个Duck typing的方法可以处理有相同行为的不同类型对象。而不是用这种方法来检查类型的。</description>
		<content:encoded><![CDATA[<p>1楼说得对</p>
<p>Duck typing就是用来关心对象的行为，而不是它是什么类型的。一个Duck typing的方法可以处理有相同行为的不同类型对象。而不是用这种方法来检查类型的。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tin</title>
		<link>http://lifesinger.org/blog/2009/02/javascript-type-check-1/comment-page-1/#comment-590</link>
		<dc:creator>Tin</dc:creator>
		<pubDate>Thu, 05 Feb 2009 08:41:32 +0000</pubDate>
		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1109#comment-590</guid>
		<description>Duck typing的作用就是约定一种行为接口，是一种比声明式接口更适合动态语言的方式。因此Prototype里面才会有Enumerable这样的Module，对于Array、Hash、或者element collection它们具有类似的行为，所以它们都是Enumerable。所以不会存在天鹅也是鸭子的问题，而应该说天鹅好像鸭子一样。</description>
		<content:encoded><![CDATA[<p>Duck typing的作用就是约定一种行为接口，是一种比声明式接口更适合动态语言的方式。因此Prototype里面才会有Enumerable这样的Module，对于Array、Hash、或者element collection它们具有类似的行为，所以它们都是Enumerable。所以不会存在天鹅也是鸭子的问题，而应该说天鹅好像鸭子一样。</p>
]]></content:encoded>
	</item>
</channel>
</rss>
