<?xml version="1.0" encoding="GB2312"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[ROR中国]]></title>
		<description><![CDATA[ROR中国]]></description>
		<generator><![CDATA[http://www.RORcn.org/]]></generator>
		<item>
			<title><![CDATA[Ruby on Rails 上海地区聚会 7月26号(完全免费并提供啤酒饮料）]]></title>
			<link>http://www.RORcn.org/List.asp?ID=46</link>
			<author><![CDATA[soinno@gmail.com]]></author>
			<pubDate><![CDATA[2008-7-3 23:42:50]]></pubDate>
			<description><![CDATA[7月26号Shanghai on Rails 上海地区聚会活动 欢迎大家积极参与，让我们一起讨论与切磋ruby和rails!<br />
<br />
[b]活动时间及地点[/b]<br />
日期：08年7月26号(暂定)<br />
时间：1:30 PM<br />
地址：未定<br />
<br />
[b]活动演讲者及主题(暂定)[/b]<br />
Eric sun,&nbsp; [url]http://www.trikr.com/[/url] 开发者<br />
演讲主题：Role based Permission<br />
<br />
Sting, 和家网(51hejia.com) CTO<br />
演讲主题：OpenSocial<br />
<br />
Quake Wang, [url]http://www.javaeye.com[/url] 开发者<br />
演讲主题: 重构你的应用- 从rails 1.x到2.x<br />
<br />
更多待定－－－－－－－－－－<br />
<br />
[b]报名方式(任选一种）[/b] <br />
如果你对这次活动感兴趣，请：<br />
1. 发邮件到 [email]shanghaionrails@googlegroups.com[/email] ， 或<br />
2. 在 [url]http://groups.google.com/group/shanghaionrails[/url] 报名， 或<br />
3. 在本帖后回复跟帖，<br />
并请提供下列信息：<br />
<br />
－ 你是否有兴趣参加？ 我们将会根据参与人数确定场地，然后发布一份正式的活动通告<br />
－ 你是否有兴趣进行演讲？我们将会随同活动公告一并发布活动日程表<br />
－ 你的姓名，联系方式（IM，EMail）<br />
<br />
[b]活动形式及目的：[/b]<br />
&nbsp;＊[b][size=6]完全免费, 并提供啤酒，饮料[/size][/b]<br />
&nbsp;＊内容包括针对Rails开发(从初学者和进阶用户)各领域的讲演<br />
&nbsp;＊旨在为Rails开发人员提供一个面对面交流与分享的平台<br />
<br />
谁应该参加？<br />
＊Ruby On Rails 爱好者<br />
＊希望了解，学习Ruby On Rails的学生，开发人员等<br />
＊正在应用或者希望应用rails的公司或企业<br />
<br />
活动组织者：<br />
Jon Hancock,&nbsp; [url]http://www.shellshadow.com[/url] <br />
Maxime Guilbot, [url]http://www.ekohe.com[/url] <br />
张元一， [url]http://www.elctech.cn[/url]<br />
Stephen]]></description>
		</item>
		<item>
			<title><![CDATA[asp.net 上传大文件,显示进度条源码]]></title>
			<link>http://www.RORcn.org/List.asp?ID=45</link>
			<author><![CDATA[rorcn@126.com]]></author>
			<pubDate><![CDATA[2008-1-4 18:27:00]]></pubDate>
			<description><![CDATA[包含asp.net 上传大文件,显示进度条源码]]></description>
		</item>
		<item>
			<title><![CDATA[国内asp.net开源项目]]></title>
			<link>http://www.RORcn.org/List.asp?ID=44</link>
			<author><![CDATA[rorcn@126.com]]></author>
			<pubDate><![CDATA[2008-1-4 18:25:02]]></pubDate>
			<description><![CDATA[<font face="Arial">国内asp.net开源项目汇集地</font>]]></description>
		</item>
		<item>
			<title><![CDATA[国内最好的正则表达式测试工具]]></title>
			<link>http://www.RORcn.org/List.asp?ID=43</link>
			<author><![CDATA[test@tom.com]]></author>
			<pubDate><![CDATA[2007-12-26 9:11:51]]></pubDate>
			<description><![CDATA[<div class="t_msgfont" id="message2">
<div id="ad_thread3_1"></div>
这是 由 阿良 开发地，本人用着非常方便，奉献给大家。<br />
喜欢这个的一定要顶一下啊。 </div>]]></description>
		</item>
		<item>
			<title><![CDATA[Asp.net学习社区]]></title>
			<link>http://www.RORcn.org/List.asp?ID=42</link>
			<author><![CDATA[test@tom.com]]></author>
			<pubDate><![CDATA[2007-12-26 9:06:04]]></pubDate>
			<description><![CDATA[很不错啊，]]></description>
		</item>
		<item>
			<title><![CDATA[Ruby中文社区开源项目平台]]></title>
			<link>http://www.RORcn.org/List.asp?ID=41</link>
			<author><![CDATA[yesbbs@hotmail.com]]></author>
			<pubDate><![CDATA[2007-7-19 22:19:50]]></pubDate>
			<description><![CDATA[Project Management System and SVN ready

大家好，很高兴的宣布Ruby中文社区的开源项目平台已经成功搭建起来了。

Ruby中文社区致力于为Ruby在中文社区的繁荣和普及贡献自己的一份力量，故架设了SVN服务器(http://svn.ruby-lang.org.cn/) 和项目管理平台(http://dev.ruby-lang.org.cn)来为开源项目提供支持。

开源项目平台使用SVN作为源代码管理工具，使用RedMine作为项目管理平台，非常感谢bob.yang把Redmine这么一个如此强大的，基于 Ruby实现的项目管理平台带到社区，也非常感谢bob.yang在平台架设过程中所表现出来的热忱及他对社区平台架设的贡献！

在此，希望各位都能够积极参与开源项目平台的建设，为Ruby中文的建设添枝加叶！

申请项目立项请在 http://ruby-lang.org.cn/forums/forumdisplay.php?fid=36 发帖申请，具体的讨论、测试等请发到下级子论坛。

为Ruby在中文社区的繁荣努力吧！]]></description>
		</item>
		<item>
			<title><![CDATA[Ruby中文社区开张]]></title>
			<link>http://www.RORcn.org/List.asp?ID=40</link>
			<author><![CDATA[yesbbs@hotmail.com]]></author>
			<pubDate><![CDATA[2007-7-5 11:16:00]]></pubDate>
			<description><![CDATA[非常高兴的宣布，ruby中国（中文）讨论社区成立了。
本讨论区将以ruby为核心，进行周边的讨论，为广大ruby的中文爱好者提供服务，希望能为ruby在中文社区的繁荣做出一点微薄的贡献！]]></description>
		</item>
		<item>
			<title><![CDATA[一个.NET程序员为什么学习Ruby on Rails?]]></title>
			<link>http://www.RORcn.org/List.asp?ID=39</link>
			<author><![CDATA[hongyuwang@tom.com]]></author>
			<pubDate><![CDATA[2007-6-24 17:54:31]]></pubDate>
			<description><![CDATA[<p class="info"> 			作者 			<strong>Stephen Chu</strong>译者 			<strong>戴强斌</strong> 			发布于 			2007年5月16日 下午9时30分 		</p>
<dl class="tags2"><dt class="community">社区</dt><dd>.NET</a>,</dd><dd>Ruby</a></dd><dt class="topics">主题</dt><dd>动态语言</a>,</dd><dd>变更</a>,</dd><dd>.NET框架</a>,</dd><dd>Ruby on Rails</a></dd></dl>
<p>你是一位资深的.NET程序员，而且已经用ASP.NET构建过许多Web应用。</p>
<p>无数个不眠之夜，为了让ASP.NET控件生命周期中的事件驱动模型按你想要的方式执行，你费尽心血，深入细节。</p>
<p>你精通于使用诸如Presentation Model、Model View Presenter这类设计模式对你的应用进行分层，以使其更易测试和维护。</p>
<p>你认为Ruby on Rails只不过是众多被吹嘘的技术中的一员。在它还没有获得可观的市场份额之前，你不会给予它过多的关注。</p>
<p>欢迎来到我的世界。如果你还在读这篇文章，我向你致敬。对于我下面的说法，你可能会充满了好奇。为什么我&mdash;&mdash;一名资深的.NET程序员，在经历了一 个月的Ruby on Rails学习后会认为：只有在我了解了Ruby on Rails之后，才能以较少的时间和编码完成以前开发过的许多应用？</p>
<p>老实说，我仍然认为.NET很棒。它为我提供了一个平台，能让我向客户源源不断地提供巨大的商业价值。但我时刻提醒自己：一个简单的问题，有大量不 同的方法和技术可以解决它，并且总有一些比其它更好。衷情于某种技术，必然会产生一些无意识的偏见，这最终会阻碍我为客户提供商业价值的能力。例如，对像 Ruby这样的动态脚本语言的了解，使我以为：与使用编译型的语言相比，我可以花费更少的时间去编写简单的自动处理的Batch/Shell脚本。</p>
<p>为什么不呢？</p>
<p>下面这几件事，是我（一个.NET程序员）学习Ruby时，发现的一些典型的不同。希望你能喜欢。 </p>
<h4>不需要编译</h4>
Ruby中没有编译的概念。一切都在运行时发生作用。有人认为代码编译可以防止编码时的粗心。那么，你可能应该去看一下测试驱动开发是怎么工作的，连续的 代码集成（当然了，不是每天都要构建），单元测试（不涉及数据库和web服务的测试）和依赖注入可以帮助你生成质量良好的代码，使你能够充满自信的灵活的 改变你的代码。编译的保障作用一下子变的不那么重要了。
<h4>动态增加类的行为&mdash;&mdash;不使用Decorator模式</h4>
在静态类型语言中，要想动态增加类的行为，我们可以使用Decorator模式或 者模板方法。而在Ruby中，有更多的方法可以在不复杂化对象设计结构的情况下，很简单地做到这一点。这只是因为语言本身对它的支持，例如：将模块作为 minxin使用，使用class_eval, instance_eval方法等。事实上，甚至可以通过编程方式在运行时定义类的方法。在静态类型语言中，也可以通过代码生成来完成它。但了解更多的方 法，可以让你向一个优秀的问题解决者迈进一步。
<p>（<strong>译者注：</strong>mixin在面向对象编程语言中是一种提供某些功能给子类继承的类，但mixin并不能实例化。从 某个mixin继承并不是什么特殊的形式，而它更适于收集功能。某个子类甚至可以通过继承一个或者多个mixin选择继承它的全部或者多数功能。一个 mixin能延期到运行时定义和绑定方法，而属性和实例参数也可在编译时才被定义。这不同于我们常见的方式，比如先定义所有的属性、方法，并在编译时进行 初始化等。）</p>
<h4>通过去除所有的类型声明和接口声明，将代码库&ldquo;瘦身&rdquo;10-20% </h4>
Ruby是一门动态类型语言。你不需要在使用变量之前声明它的类型，或者为方法签名中的参数定义合适的类型。这意味着你的代码会变得更&ldquo;瘦&rdquo;，但这是以代 码难于调试和难于进行错误跟踪为代价的，对吗？并非如此，如果你相信单元测试和良好的面向对象设计的概念。如果你的类小而紧凑，类的方法短而精良，并且经 过了很好的单元测试，那么调试和错误跟踪将会很简单。
<h4>及时Ajax化</h4>
Ruby on Rails内置对script.aculo.us库的支持（script.aculo.us是一个Ajax类库，里面包含了大量炫目的Ajax效果，使用 这些效果，可以让你的应用更具有交互友好性）。在许多情况下，这相当于在ASP.NET中将一个控件标签拖到html页面上，然后在别的地方（在 Rails中，这个地方是控制器）为其编写方法以处理Ajax在服务器端的Web请求。你的Web页面支持Ajax功能，就像Google Suggest的autocomplete或者拖拉排序那样。就这么简单。
<h4>使用Rails，不需要专门的O/R映射</h4>
使用命名惯例对数据库的表和列以及你的领域模型对象命名，可以让你忘记亲自进行O/R映射的 痛苦。Ruby on Rails会为你实现这一切。在最简单的情况下，在视图上增加一个字段并对它进行持久化，你只需要在html中增加一个文本框并在相应的数据库表中增加一 个新列，然后你就可以看到，新输入的文字被存储在了数据库新建的列中。真的，就这么简单。
<h4>用Ruby脚本构建、部署或发布应用，比使用NAnt更好。</h4>
Rake是Ruby on Rails开发中使用的标准构建工具。Rake使用Ruby语法，这意味着在构建和部署不同的应用时，你需要使用Ruby去编写你的构建脚本。作为一门语 言，Ruby在以下几个方面尤为出色：处理字符串，文件和目录的创建，高级的正则表达式支持。想一下，有多少次，你需要在批处理和NAnt脚本中执行以下 的操作：把服务器A上a目录下所有以.sql为扩展名的文件拷贝到服务器B，然后依次执行这些文件。如果你讨厌批处理脚本在编程方面的限制，或者不喜欢以 NAnt中那样的xml格式去编写脚本，你会喜欢Rake的。
<h4>不劳无获</h4>
学习Ruby的时候，我必须克服许多障碍。首先，我不得不接受这样的事实：与正在使用的&ldquo;舒适&rdquo;的技术相比，寻找Ruby的 解决方案，要花去我更多的时间。但是，用不了多久，你就会感到喜悦，因为你可以用大量的方式解决不同的问题。其次，学习Ruby/Rails让我受益非 浅，通过学以致用，加深了对知识的理解。记住，对于你曾耗费时间学过的东西，要么使用它，要么任其消逝。 <br />
<br />
<strong>查看英文原文：</strong><a href="http://www.infoq.com/articles/Netter-on-Rails%20;jsessionid=2664CE6964F1B72DF0F03E1ECAFA13D8">Why Would a .NET Programmer Learn Ruby on Rails?</a> <hr />
<strong>作者简介：</strong>Stephen Chu 是ThoughtWorks的软件开发顾问，同时也是一位经验丰富的.NET开发人员，最近关注于Ruby on Rails。您可以通过<a href="http://www.stephenchu.com/">他的博客</a>阅读他每天的新看法。
<p><strong>译者简介：</strong>戴强斌，拥有三年的Web开发经验，<a href="http://www.googlecenter.org/">武汉大学Google Camp</a>技术团队成员，目前关注垂直搜索引擎领域的应用发展。</p>]]></description>
		</item>
		<item>
			<title><![CDATA[全面理解javascript的caller,callee,call,apply概念]]></title>
			<link>http://www.RORcn.org/List.asp?ID=38</link>
			<author><![CDATA[hongyuwang@tom.com]]></author>
			<pubDate><![CDATA[2007-4-29 18:36:22]]></pubDate>
			<description><![CDATA[<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体">在提到上述的概念之前，首先想说说<span lang="EN-US">javascript</span>中函数的隐含参数：<strong style="mso-bidi-font-weight: normal"><span lang="EN-US">arguments</span></strong></font></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US"></span></strong></font><strong style="mso-bidi-font-weight: normal"><span lang="EN-US"><font face="宋体">Arguments<o:p></o:p></font></span></strong></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体">该对象代表正在执行的函数和调用它的函数的参数。<strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 14pt; LINE-HEIGHT: 150%"><o:p></o:p></span></strong></font></p>
<pre style="LINE-HEIGHT: 150%"><span lang="EN-US"><font face="宋体">[<span style="mso-field-code: ' HYPERLINK '''"><span class="MsoHyperlink"><em><u><font color="#0000ff">function</font></u></em></span></span><strong>.</strong>]<strong>arguments[</strong><span style="mso-field-code: ' HYPERLINK '''"><span class="MsoHyperlink"><em><u><font color="#0000ff">n</font></u></em></span></span><strong>]</strong></font></span></pre>
<pre style="LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><font face="宋体"><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">参数</span><br /></font></strong><em><span lang="EN-US">function</span></em><span lang="EN-US"> </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：选项。当前正在执行的</span> <strong><span lang="EN-US">Function</span></strong><span lang="EN-US"> </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的名字。</span><span lang="EN-US"> <br /></span><em><span lang="EN-US">n</span></em><span lang="EN-US"> </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：选项。要传递给</span> <strong><span lang="EN-US">Function</span></strong><span lang="EN-US"> </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的从</span><span lang="EN-US">0</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开始的参数值索引。</span> </pre>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">说明</span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%"><o:p></o:p></span></strong></p>
<p style="MARGIN: 0cm 112.45pt 0pt 0cm; LINE-HEIGHT: 150%; mso-para-margin-top: 0cm; mso-para-margin-right: 10.71gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 0cm"><font face="宋体"><strong><span lang="EN-US">Arguments</span></strong><span style="mso-bidi-font-weight: bold">是进行函数调用时，除了指定的参数外，还另外创建的一个隐藏对象。<strong><span lang="EN-US">Arguments</span></strong>是一个类似数组但不是数组的对象，说它类似数组是因为其具有数组一样的访问性质及方式，可以由<strong><span lang="EN-US">arguments[</span></strong></span><span lang="EN-US"><span style="mso-field-code: ' HYPERLINK '''"><span class="MsoHyperlink"><em><u><font color="#0000ff">n</font></u></em></span></span><strong>]</strong></span><span style="mso-bidi-font-weight: bold">来访问对应的单个参数的值，并拥有数组长度属性</span><span lang="EN-US">length</span>。还有就是<strong><span lang="EN-US">arguments</span></strong><span style="mso-bidi-font-weight: bold">对象存储的是实际传递给函数的参数，而不局限于函数声明所定义的参数列表，而且</span>不能显式创建 <strong><span lang="EN-US">arguments</span></strong><span lang="EN-US"> </span>对象。<strong><span lang="EN-US">arguments</span></strong><span lang="EN-US"> </span>对象只有函数开始时才可用。下边例子详细说明了这些性质</font><span lang="EN-US"><font face="宋体">:<br />
</font></span><strong><span lang="EN-US" style="FONT-SIZE: 13.5pt; LINE-HEIGHT: 150%; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">callee<o:p></o:p></span></strong></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 87.72%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 267px; BACKGROUND-COLOR: #eeeeee"><font face="宋体"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">arguments&nbsp;对象的用法。</span></font><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff"><font face="宋体">function</font></span><font face="宋体"><span style="COLOR: #000000">&nbsp;ArgTest(a,&nbsp;b){<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;i,&nbsp;s&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">The&nbsp;ArgTest&nbsp;function&nbsp;expected&nbsp;</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;numargs&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;arguments.length;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;获取被传递参数的数值。</span></font><span style="COLOR: #008000"><br />
</span><font face="宋体"><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;expargs&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ArgTest.length;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;获取期望参数的数值。</span></font><span style="COLOR: #008000"><br />
</span><font face="宋体"><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(expargs&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span></font><font face="宋体"><span style="COLOR: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;expargs&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;argument.&nbsp;</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br />
<font face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</font></span><font face="宋体"><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;expargs&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;arguments.&nbsp;</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(numargs&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span></font><font face="宋体"><span style="COLOR: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;numargs&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;was&nbsp;passed.</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br />
<font face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</font></span><font face="宋体"><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;numargs&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;were&nbsp;passed.</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">\n\n</span><span style="COLOR: #000000">&quot;</span></font><span style="COLOR: #000000"><br />
<font face="宋体">&nbsp;&nbsp;&nbsp;</font></span><font face="宋体"><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;numargs;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;获取参数内容。</span></font><span style="COLOR: #008000"><br />
</span><font face="宋体"><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;&nbsp;Arg&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;i&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;=&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;arguments[i]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">&quot;</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">(s);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;返回参数列表。</span></font><span style="COLOR: #008000"><br />
</span><span style="COLOR: #000000"><font face="宋体">}</font></span></div>
<p style="MARGIN: 0cm 112.45pt 0pt 0cm; LINE-HEIGHT: 150%; mso-para-margin-top: 0cm; mso-para-margin-right: 10.71gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 0cm"><br />
<font face="宋体">在此添加了一个说明arguments不是数组(Array类)的代码:<br />
</font></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 88.6%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 75px; BACKGROUND-COLOR: #eeeeee"><font face="宋体"><span style="COLOR: #000000">Array.prototype.selfvalue&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span></font><font face="宋体"><span style="COLOR: #000000">;<br />
alert(</span><span style="COLOR: #0000ff">new</span></font><font face="宋体"><span style="COLOR: #000000">&nbsp;Array().selfvalue);<br />
</span><span style="COLOR: #0000ff">function</span></font><span style="COLOR: #000000"><font face="宋体">&nbsp;testAguments(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;alert(arguments.selfvalue);<br />
}</font></span></div>
<p style="MARGIN: 0cm 112.45pt 0pt 0cm; LINE-HEIGHT: 150%; mso-para-margin-top: 0cm; mso-para-margin-right: 10.71gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 0cm"><br />
<font face="宋体">运行代码你会发现第一个alert显示1，这表示数组对象拥有selfvalue属性，值为1，而当你调用函数testAguments时，你会发现显示的是&ldquo;undefined&rdquo;，说明了不是arguments的属性，即arguments并不是一个数组对象。<br />
<br />
</font><code><strong><span lang="EN-US" style="FONT-SIZE: 14pt; LINE-HEIGHT: 150%"><font face="宋体"><span lang="EN-US" style="FONT-SIZE: 13.5pt; LINE-HEIGHT: 150%; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;caller</span><br />
</font></span></strong></code><span style="mso-bidi-font-weight: bold"><font face="宋体">&nbsp; 返回一个对函数的引用，该函数调用了当前函数。<br />
</font></span><strong><span lang="EN-US"><font face="宋体">&nbsp; functionName.caller <br />
</font></span></strong><font face="宋体"><span lang="EN-US" style="mso-bidi-font-weight: bold">&nbsp; functionName </span><span style="mso-bidi-font-weight: bold">对象是所执行函数的名称。<br />
</span></font><strong><font face="宋体">说明<br />
</font></strong><span style="mso-bidi-font-weight: bold"><font face="宋体">对于函数来说，<strong><span lang="EN-US">caller</span></strong><span lang="EN-US"> </span>属性只有在函数执行时才有定义。如果函数是由顶层调用的，那么 <strong><span lang="EN-US">caller</span></strong><span lang="EN-US"> </span>包含的就是<span lang="EN-US"> null </span>。如果在字符串上下文中使用 <strong><span lang="EN-US">caller</span></strong><span lang="EN-US"> </span>属性，那么结果和<span lang="EN-US"> functionName.toString </span>一样，也就是说，显示的是函数的反编译文本。<br />
</font></span><span style="mso-bidi-font-weight: bold"><font face="宋体">下面的例子说明了<span lang="EN-US"> caller </span>属性的用法：</font></span><br />
</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 84.29%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 166px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;caller&nbsp;demo&nbsp;{</span><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;callerDemo()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(callerDemo.caller)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;callerDemo.caller.toString();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(a);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">this&nbsp;is&nbsp;a&nbsp;top&nbsp;function</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;handleCaller()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;callerDemo();<br />
}</span></div>
<p style="MARGIN: 0cm 112.45pt 0pt 0cm; LINE-HEIGHT: 150%; mso-para-margin-top: 0cm; mso-para-margin-right: 10.71gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 0cm">&nbsp;</p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体">&nbsp;&nbsp;&nbsp; 返回正被执行的 <strong><span lang="EN-US">Function </span></strong>对象，也就是所指定的 <strong><span lang="EN-US">Function </span></strong>对象的正文。</font></p>
<pre style="LINE-HEIGHT: 150%; mso-outline-level: 1"><span lang="EN-US"><font face="宋体">[<strong><em>function</em>.</strong>]<strong>arguments.</strong><strong style="mso-bidi-font-weight: normal">callee</strong></font></span></pre>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体">可选项 <em><span lang="EN-US">function</span></em><span lang="EN-US"> </span>参数是当前正在执行的<strong><span lang="EN-US"> Function</span></strong><span lang="EN-US"> </span>对象的名称。</font></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><font face="宋体">说明<span lang="EN-US"><o:p></o:p></span></font></strong></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">callee</span></strong><span lang="EN-US"> </span>属性的初始值就是正被执行的 <strong><span lang="EN-US">Function </span></strong>对象。</font></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">callee</span></strong><span lang="EN-US"> </span>属性是 <strong><span lang="EN-US">arguments </span></strong>对象的一个成员，它表示对函数对象本身的引用，这有利于匿名<br />
函数的递归或者保证函数的封装性，例如下边示例的递归计算<span lang="EN-US">1</span>到<span lang="EN-US">n</span>的自然数之和。而该属性<br />
仅当相关函数正在执行时才可用。还有需要注意的是<strong style="mso-bidi-font-weight: normal"><span lang="EN-US">callee</span></strong>拥有<span lang="EN-US">length</span>属性，这个属性有时候<br />
用于验证还是比较好的。<strong style="mso-bidi-font-weight: normal"><span lang="EN-US">arguments.length</span></strong>是实参长度，<strong style="mso-bidi-font-weight: normal"><span lang="EN-US">arguments.callee.length</span></strong>是<br />
形参长度，由此可以判断调用时形参长度是否和实参长度一致。</font></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><font face="宋体">示例<br />
</font></strong><font face="宋体">比较一般的递归函数：</font><font face="宋体">调用时：<span lang="EN-US">alert(sum(100));<br />
</span></font><font face="宋体">其中函数内部包含了对<span lang="EN-US">sum</span>自身的引用，函数名仅仅是一个变量名，在函数内部调用<span lang="EN-US">sum</span>即相当于调用<br />
一个全局变量，不能很好的体现出是调用自身，这时使用<strong style="mso-bidi-font-weight: normal"><span lang="EN-US">callee</span></strong>会是一个比较好的方法。<br />
</font></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 89.75%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 297px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">callee可以打印其本身</span><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;calleeDemo()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;alert(arguments.callee);<br />
}<br />
</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">用于验证参数</span><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;calleeLengthDemo(arg1,&nbsp;arg2)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(arguments.length</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">arguments.callee.length)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">验证形参和实参长度正确！</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">实参长度：</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">arguments.length);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">形参长度：&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">arguments.callee.length);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">递归计算</span><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;sum&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">(n){<br />
&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(n&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;n&nbsp;＋arguments.callee(n&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br />
}</span></div>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 91.21%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 62px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;sum&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">(n){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">n)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />
</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;n&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;sum&nbsp;(n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br />
</span></div>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp;</p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 14pt; LINE-HEIGHT: 150%">apply and call<o:p></o:p></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&nbsp;&nbsp; 它们的作用都是将函数绑定到另外一个对象上去运行，两者仅在定义参数方式有所区别：</span><span lang="EN-US" style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%"><o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-FAMILY: Verdana">&nbsp;&nbsp;&nbsp; apply</span></strong><span lang="EN-US" style="FONT-FAMILY: Verdana">(thisArg,argArray);</span><span lang="EN-US" style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%"><o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-FAMILY: Verdana">&nbsp;&nbsp;&nbsp; call</span></strong><span lang="EN-US" style="FONT-FAMILY: Verdana">(thisArg[,arg1,arg2&hellip;] ]);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">即所有函数内部的</span><span lang="EN-US">this</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指针都会被赋值为</span><span lang="EN-US">thisArg</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，这可实现将函数作为另外一个对象的方法运行的目的</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: Verdana">apply</span></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的说明</span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: Verdana"><o:p></o:p></span></strong></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体">如果 <em><span lang="EN-US">argArray</span></em><span lang="EN-US"> </span>不是一个有效的数组或者不是 <strong><span lang="EN-US">arguments</span></strong><span lang="EN-US"> </span>对象，那么将导致一个<span lang="EN-US"> TypeError</span>。<br />
如果没有提供 <em><span lang="EN-US">argArray</span></em><span lang="EN-US"> </span>和 </font><span lang="EN-US" style="FONT-FAMILY: Verdana">thisArg</span><font face="宋体">任何一个参数，那么 <strong><span lang="EN-US">Global </span></strong>对象将被用作 </font><span lang="EN-US" style="FONT-FAMILY: Verdana">thisArg</span><font face="宋体"><em>，</em> <br />
并且无法被传递任何参数。</font></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><font face="宋体"><span lang="EN-US">call</span>的说明<span lang="EN-US"><o:p></o:p></span></font></strong></p>
<p style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><font face="宋体"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">call</span></strong><span lang="EN-US"> </span>方法可将一个函数的对象上下文从初始的上下文改变为由 </font><span lang="EN-US" style="FONT-FAMILY: Verdana">thisArg</span><font face="宋体">指定的新对象。<br />
如果没有提供 </font><span lang="EN-US" style="FONT-FAMILY: Verdana">thisArg</span><font face="宋体">参数，那么<span lang="EN-US"> Global </span>对象被用作 </font><span lang="EN-US" style="FONT-FAMILY: Verdana">thisArg</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相关技巧</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用</span><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">call</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">apply</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">还有一个技巧在里面，就是用</span><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">call</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">apply</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用另一个函数（类）以后，当前的<br />
函数（类）就具备了另一个函数（类）的方法或者是属性，这也可以称之为&ldquo;继承&rdquo;。看下面示例:</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"></span><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-FAMILY: Verdana">call</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">之后，</span><span lang="EN-US" style="FONT-FAMILY: Verdana">extend</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">可以继承到</span><span lang="EN-US" style="FONT-FAMILY: Verdana">base</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的方法和属性。</span><span lang="EN-US" style="FONT-FAMILY: Verdana"><o:p></o:p></span></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 90.3%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 168px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;继承的演示</span><span style="COLOR: #008000"><br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;base()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.member&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;dnnsun_Member</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.method&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.member);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;extend()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;base.call(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;window.alert(member);<br />
&nbsp;&nbsp;&nbsp;&nbsp;window.alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.method);<br />
}</span></div>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><br />
上面的例子可以看出，通过</p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span lang="EN-US" style="FONT-FAMILY: Verdana"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">顺便提一下，在</span><span lang="EN-US" style="FONT-FAMILY: Verdana">javascript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">框架</span><span lang="EN-US" style="FONT-FAMILY: Verdana">prototype</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">里就使用</span><span lang="EN-US" style="FONT-FAMILY: Verdana">apply</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">来创建一个定义类的模式，</span><span lang="EN-US" style="FONT-FAMILY: Verdana"><o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">其实现代码如下：</span><code><span style="FONT-SIZE: 12pt; LINE-HEIGHT: 150%"><font face="宋体"></font></span></code></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 85.75%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 178px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;Class&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;{<br />
&nbsp;&nbsp;create:&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.initialize.apply(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">,&nbsp;arguments);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}</span></div>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">解析：从代码看<span lang="EN-US">,</span>该对象仅包含一个方法：<span lang="EN-US">Create</span>，其返回一个函数，即类。但这也同时是类的<br />
构造函数，其中调用<span lang="EN-US">initialize</span>，而这个方法是在类创建时定义的初始化函数。通过如此途径，<br />
就可以实现<span lang="EN-US">prototype</span>中的类创建模式<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">示例</span></strong><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">：</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"></span><span lang="EN-US" style="FONT-FAMILY: Verdana">prototype</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">信息请到其官方网站查看。</span><span lang="EN-US" style="FONT-FAMILY: Verdana"><o:p></o:p></span></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 86.74%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 179px; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;vehicle</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Class.create();<br />
vehicle.prototype</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{<br />
&nbsp;&nbsp;&nbsp;&nbsp;initialize:</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">(type){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">type;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;showSelf:</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">this&nbsp;vehicle&nbsp;is&nbsp;</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.type);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
<br />
</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;moto</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;vehicle(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">Moto</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">);<br />
moto.showSelf();<br />
</span></div>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%"><br />
更详细的关于</p>]]></description>
		</item>
		<item>
			<title><![CDATA[javascript apply()方法]]></title>
			<link>http://www.RORcn.org/List.asp?ID=37</link>
			<author><![CDATA[hongyuwang@tom.com]]></author>
			<pubDate><![CDATA[2007-4-29 18:35:05]]></pubDate>
			<description><![CDATA[<p>
<table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div class="cnt">
            <pre><div>通过一个例子说明apply()的用法：</div><div>//针对各种浏览器建立一个http request的对象</div><br /><div>function getHttpRequest(){<br />&nbsp;&nbsp;http_request = null;<br />&nbsp;&nbsp;if (window.XMLHttpRequest) {&nbsp;</div><br /><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http_request = new XMLHttpRequest();<br />&nbsp;&nbsp;} else if (window.ActiveXObject) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http_request = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return http_request;<br />}</div><br /><div>var ajax_request;</div><br /><div>functiong getPerson(){</div><br /><div>&nbsp; ajax_request = getHttpRequest();&nbsp;&nbsp;&nbsp; //建立一个http request</div><br /><div>&nbsp; ajax_request.onstatechange = handleResponse;&nbsp; //指定回调函数</div><br /><div>&nbsp; ajax_request.open(&quot;GET&quot;, &quot;<a href="http://myhost.com/sample.xm">http://myhost.com/sample.xm</a>l&quot;, null);</div><br /><div>&nbsp; ajax_request.send();</div><br /><div>}</div><br /><div>&nbsp;</div><br /><div>function handleResponse(){</div><br /><div>&nbsp; if(ajax_request.readyState != 4) return;</div><br /><div>&nbsp; if(ajax_request.status == 200){</div><br /><div>&nbsp;&nbsp;&nbsp; var xml = ajax_request.responseXML;</div><br /><div>&nbsp;&nbsp;&nbsp; /*&nbsp;对获得的xml的处理 */</div><br /><div>&nbsp; }</div><br /><div>}</div><br /><div>&nbsp;</div><br /><div>调用的时候可以直接在页面里调用</div><br /><div>getPerson();</div><br /><div>&nbsp;</div><br /><div>这个函数会建立一个httpRequest对象，然后发送请求，在请求返回的时候会自动调用handleResponse函数来完成操作。</div><br /><div>在简单的环境上，上述代码会工作得很好，但是如果在一个页面中要执行多次这种操作就比较麻烦了，需要写多个函数，看一下上面的定义：</div><br /><div>var ajax_request; 表示这是个全局变量，多次请求的时候每个请求都要用到这个对象，ajax又是异步的，无法事先确定哪个请求先返回。</div><br /><div>&nbsp;</div><br /><div>如果把ajax_request作为函数内的局部变量呢？那样如果在handleResponse里能看到ajax_request对象就可以解决这个问题了。</div><br /><div>可以考虑把ajax_request作为一个参数传递给handleResponse，现在的问题是，对handleResponse的调用是自动的，怎么能在参数列表中添加这个参数呢？我们想到了this变量，在javascript中，所有的东西都是对象，this表示当前对象，在函数中this就表示当前的函数。</div><br /><div>javascript提供了一种可以改变this的方法&mdash;&mdash;apply()。</div><br /><div>javascript对apply的解释是：使用指定对象替换当前对象并调用函数。比如：</div><br /><div>&nbsp;</div><br /><div>function test_apply(){</div><br /><div>&nbsp; alert(this);</div><br /><div>}</div><br /><div>test_apply.apply(document, []);</div><br /><div>&nbsp;</div><br /><div>就表示调用函数test_apply，并用document对象来替换test_apply中的this。</div><br /><div>&nbsp;</div><br /><div>回到刚刚的问题，为了修改当前对象，需要在指定handleResponse的时候就修改this对象。ajax_request.onstatechange是一个函数的句柄，只要我把一个函数的句柄赋值给它就可以了，同时函数也是一种对象，Function对象，因此我们为函数对象添加一个方法：</div><br /><div>Function.prototype.setThis(){</div><br /><div>&nbsp; var curr_function = this;</div><br /><div>&nbsp; var to_this_object = arguments[0];</div><br /><div>&nbsp; return function(){</div><br /><div>&nbsp;&nbsp;&nbsp; currFunc.apply(to_this_object, []);</div><br /><div>&nbsp; };</div><br /><div>}</div><br /><div>&nbsp;</div><br /><div>下面，修改getPerson为：</div><br /><div><br /><div>functiong getPerson(){</div><br /><div>&nbsp; var tmp_request = getHttpRequest();&nbsp;&nbsp;&nbsp; //建立一个http request</div><br /><div>&nbsp; tmp_request.onstatechange = handleResponse.setThis(tmp_request);&nbsp; //指定回调函数</div><br /><div>&nbsp; tmp_request.open(&quot;GET&quot;, &quot;<a href="http://myhost.com/sample.xm">http://myhost.com/sample.xm</a>l&quot;, null);</div><br /><div>&nbsp; tmp_request.send();</div><br /><div>}</div></div><br /><div>&nbsp;</div><br /><div>修改handleResponse为：</div><br /><div><br /><div>function handleResponse(){</div><br /><div>&nbsp; if(this.readyState != 4) return;</div><br /><div>&nbsp; if(this.status == 200){</div><br /><div>&nbsp;&nbsp;&nbsp; var xml = this.responseXML;</div><br /><div>&nbsp;&nbsp;&nbsp; /*&nbsp;对获得的xml的处理 */</div><br /><div>&nbsp; }</div><br /><div>}</div><br /><div>即可。</div><br /><div>具体的变化就在于tmp_request.onstatechange = handleResponse.setThis(tmp_request);&nbsp; </div><br /><div>因为handleResponse是一个函数，因此它具有Function新添加的方法setThis，</div><br /><div>下面来看setThis方法：</div><br /><div>var curr_function = this;&nbsp; //获得当前的函数本身<br /><div>var to_this_object = arguments[0];&nbsp; //获得要指定的新的this对象</div><br /><div>return function(){</div><br /><div>&nbsp;&nbsp;&nbsp; currFunc.apply(to_this_object, []);</div><br /><div>&nbsp; };</div><br /><div>&nbsp;</div><br /><div>这里的返回值是一个函数，即当tmp_request的onstatechange事件的时候会触发这个函数，该函数中只有一句</div><br /><div>currFunc.apply(to_this_object, []);即用to_this_object替换当前对象并调用currFunc，在这里currFunc即代表了handleResponse，因此调用handleResponse，因为已经修改了其this对象，因此在handleResponse中用this即代表了tmp_request对象。</div><br /><div>用这种方法可以减化代码，并使代码更具可重用性。<br />源文地址：http://www.cublog.cn/opera/showart.php?blogid=21787&amp;id=140549<br /><br /><font color="#339966">附注：<br /></font><p>应用某一对象的一个方法，用另一个对象替换当前对象。</p><br /><code><font face="新宋体"><strong>apply(</strong>[<em>thisObj</em>[,<em>argArray</em>]]<strong>)</strong></font></code>参数thisObj可选项。将被用作当前对象的对象。<br /><p class="dt">argArray</p>可选项。将被传递给该函数的参数数组。<br /><h4>说明</h4>如果 <em>argArray</em> 不是一个有效的数组或者不是 <strong>arguments</strong> 对象，那么将导致一个 TypeError。如果没有提供 <em>argArray</em> 和 <em>thisObj</em> 任何一个参数，那么 <strong>Global </strong>对象将被用作 <em>thisObj，</em> 并且无法被传递任何参数。</div></div></div></pre>
            </div>
            </td>
        </tr>
    </tbody>
</table>
</p>
<div class="tit"></div>
<div class="tit">javascript apply()方法二</div>
<div class="date"></div>
<p>
<table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div class="cnt"><font face="arial, helvitica" size="2"><strong><span class="OBJECT">Function.</span><span class="METHOD">apply</span><span class="ARGUMENT">(thisArg[, argArray])</span></strong> <br />
            &nbsp;<br />
            The <strong>apply</strong> method allows you to call a function and specify what the keyword <strong>this</strong> will refer to within the context of that function. The thisArg argument should be an object. Within the context of the function being called, <strong>this</strong> will refer to thisArg. The second argument to the <strong>apply</strong> method is an array. The elements of this array will be passed as the arguments to the function being called. The argArray parameter can be either an array literal or the deprecated <strong>arguments</a></strong> property of a function. <br />
            &nbsp;<br />
            The <strong>apply</strong> method can be used to simulate object inheritance as in the following example. We first define the constructor for an object called Car which has three properties. Then the constructor for a second object called RentalCar is defined. RentalCar will inherit the properties of Car and add one additional property of its own - carNo. The RentalCar constructor uses the <strong>apply</strong> method to call the Car constructor, passing itself as thisArg. Therefore, inside the Car function, the keyword <strong>this</strong> actually refers to the RentalCar object being constructed, and not a new Car object. By this means,the RentalCar object inherits the properties from the Car object. <br />
            &nbsp;<br />
            Code:<br />
            <font color="#000000"><font face="Arial"><span class="CODE">function Car(make, model, year) <br />
            {<br />
            &nbsp;&nbsp;this.make = make;<br />
            &nbsp;&nbsp;this.model = model;<br />
            &nbsp;&nbsp;this.year = year;<br />
            }</span> </font></font><span class="CODE"><br />
            <font face="Arial" color="#000000">&nbsp;<br />
            function RentalCar(carNo, make, model, year) <br />
            {<br />
            &nbsp;&nbsp;this.carNo = carNo;<br />
            &nbsp;&nbsp;Car.apply(this, new Array(make, model, year))<br />
            } <br />
            &nbsp;<br />
            myCar = new RentalCar(2134,&quot;Ford&quot;,&quot;Mustang&quot;,1998)<br />
            document.write(&quot;Your car is a &quot; + myCar.year + &quot; &quot; +<br />
            &nbsp;&nbsp;myCar.make + &quot; &quot; + myCar.model + &quot;.&quot;) </font></span><br />
            &nbsp;<br />
            Output:<br />
            <span class="OUTPUT">Your car is a 1998 Ford Mustang. </span><br />
            &nbsp;<br />
            NOTE: The <strong>apply</strong> method is very similar to the <strong>call</a></strong> method and only differs in that, up until now, you could use the deprecated <strong>arguments</strong> array as one of its parameters<br />
            <br />
            手册中的说明是<br />
            </font>
            <h2><a name="Head2Ref;"></a><a name="1194017"><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000"> </font></a></h2>
            <a name="1194019"><font color="#000000">Allows you to </font><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000"> a method of another object in the context of a different object (the calling object). </font></a>
            <table border="0">
                <tbody>
                    <tr>
                        <td valign="baseline" align="left">
                        <p><a name="1196931"><em><font color="#000000">Method of</font></em></a></p>
                        </td>
                        <td valign="baseline" align="left">
                        <p><a name="1196936"></a><code><font face="新宋体">Function</font></code></a></p>
                        </td>
                    </tr>
                    <tr>
                        <td valign="baseline" align="left">
                        <p><a name="1196938"><em><font color="#000000">Implemented in</font></em></a></p>
                        </td>
                        <td valign="baseline" align="left">
                        <p><a name="1196940"><font color="#000000">JavaScript 1.3</font></a></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            <h4><a name="Head3;"></a><a name="1194032"><font color="#000000">Syntax </font></a></h4>
            <pre><a name="1194033"><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000">(<em>thisArg</em>[, <em>argArray</em>])</font></a></pre>
            <h4><a name="Head3;"></a><a name="1194034"><font color="#000000">Parameters </font></a></h4>
            <a name="1194044"></a>
            <table border="0">
                <tbody>
                    <tr>
                        <td valign="baseline" align="left">
                        <pre><a name="1194037"><font color="#000000">thisArg</font></a></pre>
                        </td>
                        <td valign="baseline" align="left">
                        <p><a name="1194039"><font color="#000000">Parameter for the calling object</font></a></p>
                        </td>
                    </tr>
                    <tr>
                        <td valign="baseline" align="left">
                        <pre><a name="1194041"><font color="#000000">argArray</font></a></pre>
                        </td>
                        <td valign="baseline" align="left">
                        <p><a name="1194043"><font color="#000000">An argument array for the object</font></a></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            <h4><a name="Head3;"></a><a name="1194045"><font color="#000000">Description </font></a></h4>
            <a name="1194046"><font color="#000000">You can assign a different <code><font face="新宋体">this</font></code> object when calling an existing function. <code><font face="新宋体">this</font></code> refers to the current object, the calling object. With </font><code><font style="BACKGROUND-COLOR: rgb(46,74,153)" face="新宋体" color="#ffffff">apply</font></code><font color="#000000">, you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.</font></a> <a name="1194047"><code><font style="BACKGROUND-COLOR: rgb(46,74,153)" face="新宋体" color="#ffffff">apply</font></code><font color="#000000"> is very similar to <code><font face="新宋体">call</font></code>, except for the type of arguments it supports. You can use an arguments array instead of a named set of parameters. With </font><code><font style="BACKGROUND-COLOR: rgb(46,74,153)" face="新宋体" color="#ffffff">apply</font></code><font color="#000000">, you can use an array literal, for example, </font><code><font face="新宋体"><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000">(this, [name, value])</font></font></code><font color="#000000">, or an <code><font face="新宋体">Array</font></code> object, for example, </font><code><font face="新宋体"><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000">(this, new Array(name, value))</font></font></code><font color="#000000">.</font></a> <a name="1209502"><font color="#000000">You can also use </font></a><code><font face="新宋体">arguments</font></code></a> for the <code><font face="新宋体">argArray</font></code> parameter. <code><font face="新宋体">arguments</font></code> is a local variable of a function. It can be used for all unspecified arguments of the called object. Thus, you do not have to know the arguments of the called object when you use the <code><font style="BACKGROUND-COLOR: rgb(46,74,153)" face="新宋体" color="#ffffff">apply</font></code> method. You can use <code><font face="新宋体">arguments</font></code> to pass all the arguments to the called object. The called object is then responsible for handling the arguments.
            <h4><a name="Head3;"></a><a name="1194049"><font color="#000000">Examples </font></a></h4>
            <a name="1194050"><font color="#000000">You can use </font><code><font style="BACKGROUND-COLOR: rgb(46,74,153)" face="新宋体" color="#ffffff">apply</font></code><font color="#000000"> to chain constructors for an object, similar to Java. In the following example, the constructor for the <code><font face="新宋体">product</font></code> object is defined with two parameters, <code><font face="新宋体">name</font></code> and <code><font face="新宋体">value</font></code>. Another object, <code><font face="新宋体">prod_dept</font></code>, initializes its unique variable (<code><font face="新宋体">dept</font></code>) and calls the constructor for <code><font face="新宋体">product</font></code> in its constructor to initialize the other variables. In this example, the parameter <code><font face="新宋体">arguments</font></code> is used for all arguments of the <code><font face="新宋体">product</font></code> object's constructor.</font></a>
            <pre><a name="1194051"><font color="#000000">function product(name, value){<br />&nbsp;&nbsp;&nbsp;this.name = name;<br />&nbsp;&nbsp;&nbsp;if(value &gt; 1000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = 999;<br />&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = value;<br />}</font></a></pre>
            <pre><a name="1194052"><font color="#000000">function prod_dept(name, value, dept){<br />&nbsp;&nbsp;&nbsp;this.dept = dept;<br />&nbsp;&nbsp;&nbsp;product.</font><font style="BACKGROUND-COLOR: rgb(46,74,153)" color="#ffffff">apply</font><font color="#000000">(product, arguments);<br />}</font></a></pre>
            <pre><a name="1194053"><font color="#000000">prod_dept.prototype = new product();</font></a></pre>
            <pre><a name="1194054"><font color="#000000">// since 5 is less than 100 value is set<br />cheese = new prod_dept(&quot;feta&quot;, 5, &quot;food&quot;);</font></a></pre>
            <pre><a name="1194055"><font color="#000000">// since 5000 is above 1000, value will be 999<br />car = new prod_dept(&quot;honda&quot;, 5000, &quot;auto&quot;);</font></a></pre>
            </div>
            </td>
        </tr>
    </tbody>
</table>
</p>]]></description>
		</item>
	</channel>
</rss>