<?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>G法师的实验室 &#187; 相等</title>
	<atom:link href="http://www.jatx.org/archives/tag/%e7%9b%b8%e7%ad%89/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jatx.org</link>
	<description>I&#039;m Jser</description>
	<lastBuildDate>Fri, 27 Jan 2012 10:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>双等号的比较原理</title>
		<link>http://www.jatx.org/archives/119</link>
		<comments>http://www.jatx.org/archives/119#comments</comments>
		<pubDate>Sun, 09 May 2010 05:42:27 +0000</pubDate>
		<dc:creator>G法师</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[双等]]></category>
		<category><![CDATA[相等]]></category>

		<guid isPermaLink="false">http://www.jatx.net/archives/119</guid>
		<description><![CDATA[ [...]]]></description>
			<content:encoded><![CDATA[<p>直接摘自ECMA262</p>
<p><strong>章节号：11.9.3 The Abstract Equality Comparison Algorithm</strong>   </p>
<p>比较 x == y, 当 x 和 y 都是值的时候, 产生<span style="color: blue; font-weight: bold">true</span>或<span style="color: blue; font-weight: bold">false</span>. 这样的一个比较执行如下：
<ol>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is the same as <span style="font-style: italic; color: green">Type</span>(y), then
<ol style="list-style-type: lower-alpha">
<li>If <span style="font-style: italic; color: green">Type</span>(x) is <span style="color: red; font-weight: bold">undefined</span>, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Null, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Number, then
<ol style="list-style-type: upper-roman">
<li>If x is <span style="color: red; font-weight: bold">NaN</span>, return <span style="color: blue; font-weight: bold">false</span>. </li>
<li>If y is <span style="color: red; font-weight: bold">NaN</span>, return <span style="color: blue; font-weight: bold">false</span>. </li>
<li>If x is the same Number value as y, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If x is +0 and y is −0, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If x is −0 and y is +0, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>Return <span style="color: blue; font-weight: bold">false</span>. </li>
</ol>
</li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is String, then return <span style="color: blue; font-weight: bold">true</span> if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return <span style="color: blue; font-weight: bold">false</span>. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Boolean, return <span style="color: blue; font-weight: bold">true</span> if x and y are both <span style="color: blue; font-weight: bold">true</span> or both <span style="color: blue; font-weight: bold">false</span>. Otherwise, return <span style="color: blue; font-weight: bold">false</span>. </li>
<li>Return <span style="color: blue; font-weight: bold">true</span> if x and y refer to the same object. Otherwise, return <span style="color: blue; font-weight: bold">false</span>. </li>
</ol>
</li>
<li>If x is null and y is <span style="color: red; font-weight: bold">undefined</span>, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If x is <span style="color: red; font-weight: bold">undefined</span> and y is null, return <span style="color: blue; font-weight: bold">true</span>. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Number and <span style="font-style: italic; color: green">Type</span>(y) is String, return the result of the comparison x == <span style="font-style: italic; color: green">ToNumber</span>(y). </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is String and <span style="font-style: italic; color: green">Type</span>(y) is Number,       <br />return the result of the comparison <span style="font-style: italic; color: green">ToNumber</span>(x) == y. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Boolean, return the result of the comparison <span style="font-style: italic; color: green">ToNumber</span>(x) == y. </li>
<li>If <span style="font-style: italic; color: green">Type</span>(y) is Boolean, return the result of the comparison x == <span style="font-style: italic; color: green">ToNumber</span>(y). </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is either String or Number and <span style="font-style: italic; color: green">Type</span>(y) is Object,       <br />return the result of the comparison x == <span style="font-style: italic; color: green">ToPrimitive</span>(y). </li>
<li>If <span style="font-style: italic; color: green">Type</span>(x) is Object and <span style="font-style: italic; color: green">Type</span>(y) is either String or Number,       <br />return the result of the comparison <span style="font-style: italic; color: green">ToPrimitive</span>(x) == y. </li>
<li>Return <span style="color: blue; font-weight: bold">false</span>. </li>
</ol>
<p>NOTE 1 鉴于以上相等的定义：   <br />• 可以这样强制字符串比较： &quot;&quot; + a == &quot;&quot; + b.   <br />• 可以这样强制数字比较： +a == +b.   <br />• 可以这样强制布尔值比较：!a == !b.   <br />NOTE 2 双等比较保持以下的不变式：   <br />•&#160; A != B 等价于 !(A == B).   <br />•&#160; A == B 等价于 B == A, 除了A和B求值的顺序不同   <br />NOTE 3 The equality operator is not always transitive. For example, there might be two distinct String objects, each   <br />representing the same String value; each String object would be considered equal to the String value by the == operator,   <br />but the two String objects would not be equal to each other.   <br />NOTE 4 Comparison of Strings uses a simple equality test on sequences of code unit values. There is no attempt to   <br />use the more complex, semantically oriented definitions of character or string equality and collating order defined in the   <br />Unicode specification. Therefore Strings values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalised form.
<p><em>最近这部分待译</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jatx.org/archives/119/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

