﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-扬帆出海-文章分类-Js、Ajax</title><link>http://www.blogjava.net/liu0909/category/41260.html</link><description>学习,永无止境.......</description><language>zh-cn</language><lastBuildDate>Thu, 27 Aug 2009 00:34:08 GMT</lastBuildDate><pubDate>Thu, 27 Aug 2009 00:34:08 GMT</pubDate><ttl>60</ttl><item><title>【Ext】Grid小问题解决(不断增加中)</title><link>http://www.blogjava.net/liu0909/articles/292563.html</link><dc:creator>扬帆出海</dc:creator><author>扬帆出海</author><pubDate>Tue, 25 Aug 2009 12:59:00 GMT</pubDate><guid>http://www.blogjava.net/liu0909/articles/292563.html</guid><wfw:comment>http://www.blogjava.net/liu0909/comments/292563.html</wfw:comment><comments>http://www.blogjava.net/liu0909/articles/292563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liu0909/comments/commentRss/292563.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liu0909/services/trackbacks/292563.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
现在的项目使用Ext2做界面布局以及表格展示，其中遇到的小问题及其解决方法记录下来，以便大家一起学习。<br />
<p><strong><font size="4">1、Grid滚动条</font></strong></p>
<p>&nbsp;&nbsp;&nbsp; <strong>Grid不显示水平滚动条的办法：</strong></p>
<p>&nbsp;&nbsp;&nbsp; 在grid创建之后，或grid重新动态配置之后，加入下面两行代码即可</p>
<p>&nbsp;&nbsp;&nbsp; this.grid.getView().mainBody.dom.style.width = this.grid.getView().getTotalWidth();<br />
&nbsp;&nbsp;&nbsp; this.grid.getView().mainBody.dom.style.height = '1px';<br />
<br />
&nbsp;&nbsp;&nbsp; 注：this.grid为创建的grid</p>
<p><strong>&nbsp;&nbsp; 控制滚动条位置</strong></p>
<p><span><span>&nbsp;&nbsp; grid.getSelectionModel().selectFirstRow();</span><span class="comment">//第一行 </span><span>&nbsp;&nbsp;<br />
</span></span><span>&nbsp;&nbsp; grid.getSelectionModel().selectLastRow() ;</span><span class="comment">//最后一行 </span><span>&nbsp;&nbsp;<br />
</span><span>&nbsp;&nbsp; grid.getView().focusRow(grid.getStore().getCount()-1);</span><span class="comment">//指定行 <br />
<br />
<strong>2、让ExtJs的Grid单元格显示竖线<br />
</strong></p>
<p><span class="hilite1"><font style="background-color: #ffff00">Ext</font></span> GridPanel 的默认样式的单元格没有显示竖线，若要显示可在页面中加入以下CSS样式：</p>
<div class="source" style="background-color: #f9f7ed; apos: "><span style="font-weight: bold">&lt;</span><strong><span style="color: #000080">style</span> <span style="color: #000080">type</span><span style="font-weight: bold">=</span><span style="color: #bb8844">&#8220;text/css&#8221;</span><span style="font-weight: bold">&gt;</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-cell-inner</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">border-right</span><span style="font-weight: bold">: </span><span style="color: #009999">1px</span> <span style="font-weight: bold">solid</span> <span style="color: #009999">#eceff6</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
<span style="font-weight: bold">&lt;/</span><span style="color: #000080">style</span><span style="font-weight: bold">&gt;</span></strong></div>
<p>然后发现竖线与表头没有对齐，有一个像素的误差，再加入样式，代码就成了这样：</p>
<div class="source" style="background-color: #f9f7ed; apos: "><span style="font-weight: bold">&lt;</span><strong><span style="color: #000080">style</span> <span style="color: #000080">type</span><span style="font-weight: bold">=</span><span style="color: #bb8844">&#8220;text/css&#8221;</span><span style="font-weight: bold">&gt;</span><br />
&nbsp;&nbsp;&nbsp; <span style="color: #999988; font-style: italic">/*显示竖线*/</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-cell-inner</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">border-right</span><span style="font-weight: bold">: </span><span style="color: #009999">1px</span> <span style="font-weight: bold">solid</span> <span style="color: #009999">#eceff6</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; <span style="color: #999988; font-style: italic">/*与表头对齐*/</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-row</span> <span style="color: #000080">td</span><span style="font-weight: bold">,</span> <span style="font-weight: bold; color: #445588">.x-grid3-summary-row</span> <span style="color: #000080">td</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">padding-right</span><span style="font-weight: bold">:</span> <span style="color: #009999">0px</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
<span style="font-weight: bold">&lt;/</span><span style="color: #000080">style</span><span style="font-weight: bold">&gt;</span></strong></div>
<p>接着发现行间有一个像素的间隔，再改吧，代码如下：</p>
<div class="source" style="background-color: #f9f7ed; apos: "><span style="font-weight: bold">&lt;</span><strong><span style="color: #000080">style</span> <span style="color: #000080">type</span><span style="font-weight: bold">=</span><span style="color: #bb8844">&#8220;text/css&#8221;</span><span style="font-weight: bold">&gt;</span><br />
&nbsp;&nbsp;&nbsp; <span style="color: #999988; font-style: italic">/*显示竖线*/</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-cell-inner</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">border-right</span><span style="font-weight: bold">: </span><span style="color: #009999">1px</span> <span style="font-weight: bold">solid</span> <span style="color: #009999">#eceff6</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; <span style="color: #999988; font-style: italic">/*与表头对齐*/</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-row</span> <span style="color: #000080">td</span><span style="font-weight: bold">,</span> <span style="font-weight: bold; color: #445588">.x-grid3-summary-row</span> <span style="color: #000080">td</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">padding-right</span><span style="font-weight: bold">:</span> <span style="color: #009999">0px</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; <span style="color: #999988; font-style: italic">/*去掉行间空白*/</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold; color: #445588">.x-grid3-row</span> {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">border-top-width</span><span style="font-weight: bold">: </span><span style="color: #009999">0px</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold">border-bottom-width</span><span style="font-weight: bold">: </span><span style="color: #009999">0px</span>;<br />
&nbsp;&nbsp;&nbsp; }<br />
<span style="font-weight: bold">&lt;/</span><span style="color: #000080">style</span><span style="font-weight: bold">&gt;</span></strong></div>
<br />
以后会把遇到的问题及其解决方法继续添加。。。。</span>
<img src ="http://www.blogjava.net/liu0909/aggbug/292563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liu0909/" target="_blank">扬帆出海</a> 2009-08-25 20:59 <a href="http://www.blogjava.net/liu0909/articles/292563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转载】js的继承实现方式</title><link>http://www.blogjava.net/liu0909/articles/290821.html</link><dc:creator>扬帆出海</dc:creator><author>扬帆出海</author><pubDate>Wed, 12 Aug 2009 06:33:00 GMT</pubDate><guid>http://www.blogjava.net/liu0909/articles/290821.html</guid><wfw:comment>http://www.blogjava.net/liu0909/comments/290821.html</wfw:comment><comments>http://www.blogjava.net/liu0909/articles/290821.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liu0909/comments/commentRss/290821.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liu0909/services/trackbacks/290821.html</trackback:ping><description><![CDATA[第一种 prototype 引用型原型继承<br />
语言支持：js原生支持的继承方式 构造器的的prototype属性作为类的原型 每个该类的对象都持有一个到原型的引用 当对象中的属性不存在时 可以访问原型的属性<br />
代码示例：<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.x</span><span style="color: #000000">=</span><span style="color: #000000">10</span><span style="color: #000000">;<br />
}<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){<br />
}<br />
child.prototype</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;parent();<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.x);<br />
</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
第二种 复制型原型继承<br />
语言支持：js new运算符的性质 当构造函数return值为非空对象时 new表达式返回return的对象<br />
代码示例：<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.x</span><span style="color: #000000">=</span><span style="color: #000000">10</span><span style="color: #000000">;<br />
}<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;ret</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;parent();<br />
&nbsp;&nbsp;&nbsp;&nbsp;ret.y</span><span style="color: #000000">=</span><span style="color: #000000">20</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;ret;<br />
}<br />
<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.x);</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
第三种 类继承 属性抄写<br />
语言支持：for in枚举对象所有属性<br />
代码：<br />
<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.x</span><span style="color: #000000">=</span><span style="color: #000000">10</span><span style="color: #000000">;<br />
}<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;parentObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;parent();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;parentObj)</span><span style="color: #0000ff">this</span><span style="color: #000000">[p]</span><span style="color: #000000">=</span><span style="color: #000000">parentObj[p];<br />
}<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.x);</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
第四种 类继承 对象冒充<br />
语言支持： 1.动态添加和删除方法 2.函数的call和apply<br />
代码：<br />
用语言支持1实现的类继承<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.x</span><span style="color: #000000">=</span><span style="color: #000000">10</span><span style="color: #000000">;<br />
}<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.parent</span><span style="color: #000000">=</span><span style="color: #000000">parent;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.parent();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">delete</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.parent;<br />
}<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.x);</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
用语言支持2实现的类继承<br />
<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.x</span><span style="color: #000000">=</span><span style="color: #000000">10</span><span style="color: #000000">;<br />
}<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;parent.call(</span><span style="color: #0000ff">this</span><span style="color: #000000">);<br />
}<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.x);</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
第五种 原型抄写<br />
语言支持：通过修改类的原型对象 可以为一类对象添加属性和方法<br />
代码：<br />
<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(){}<br />
parent.prototype.me</span><span style="color: #000000">=</span><span style="color: #0000ff">function</span><span style="color: #000000">(){alert(</span><span style="color: #000000">"</span><span style="color: #000000">parent</span><span style="color: #000000">"</span><span style="color: #000000">)};<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;child(){}<br />
</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;parent.prototype)child.prototype[p]</span><span style="color: #000000">=</span><span style="color: #000000">parent.prototype[p];<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
childObj.me();</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
第六种 元类<br />
语言支持: js函数都是对象 且js函数可被构造<br />
代码：<br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;parent(string){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;child</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Function(</span><span style="color: #000000">"</span><span style="color: #000000">this.x=10;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">string);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;child;<br />
}<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;child</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;parent(</span><span style="color: #000000">"</span><span style="color: #000000">this.y=20;</span><span style="color: #000000">"</span><span style="color: #000000">);<br />
<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;childObj</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;child();<br />
alert(childObj.y);<br />
</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
<font color="#000000"><span style="font-size: 9pt; font-family: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">以下通过混合构造函数与原型方式来实现</span><span lang="EN-US" style="font-size: 9pt; font-family: Verdana">JS</span><span style="font-size: 9pt; font-family: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的继承功能。</span><span lang="EN-US" style="font-size: 9pt; font-family: Verdana"> Polygon</span><span style="font-size: 9pt; font-family: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">为父类，</span><span lang="EN-US" style="font-size: 9pt; font-family: Verdana">Triangle Rectangle </span><span style="font-size: 9pt; font-family: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">为子类。</span></font><span lang="EN-US" style="font-size: 9pt; font-family: Verdana"><br />
</span><br />
<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: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;Polygon&nbsp;(iSiders){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.sides&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iSiders;<br />
}<br />
Polygon.prototype.getArea&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">function</span><span style="color: #000000">(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />
}<br />
<br />
<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;Triangle(iBase,iHeight){<br />
&nbsp;&nbsp;&nbsp;&nbsp;Polygon.call(</span><span style="color: #0000ff">this</span><span style="color: #000000">,</span><span style="color: #000000">3</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.base&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iBase;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.height&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iHeight;<br />
}<br />
Triangle.prototype&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Polygon();<br />
Triangle.prototype.getArea&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">function</span><span style="color: #000000">(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0.5</span><span style="color: #000000">*</span><span style="color: #0000ff">this</span><span style="color: #000000">.base</span><span style="color: #000000">*</span><span style="color: #0000ff">this</span><span style="color: #000000">.height;<br />
}<br />
<br />
</span><span style="color: #0000ff">function</span><span style="color: #000000">&nbsp;Rectangle(iLength,iWidth){<br />
&nbsp;&nbsp;&nbsp;&nbsp;Polygon.call(</span><span style="color: #0000ff">this</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.length&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iLength;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.width&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iWidth;<br />
}<br />
Rectangle.prototype&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Polygon();<br />
Rectangle.prototype.getArea&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">function</span><span style="color: #000000">(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.length</span><span style="color: #000000">*</span><span style="color: #0000ff">this</span><span style="color: #000000">.width;<br />
}<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;triangle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Triangle(</span><span style="color: #000000">12</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">);<br />
</span><span style="color: #0000ff">var</span><span style="color: #000000">&nbsp;rectangle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Rectangle(</span><span style="color: #000000">22</span><span style="color: #000000">,</span><span style="color: #000000">10</span><span style="color: #000000">);<br />
alert(triangle.getArea);<br />
alert(rectangle.getArea);</span></div>
<br />
原文：http://blog.csdn.net/lenotang/archive/2008/08/27/2840315.aspx
<img src ="http://www.blogjava.net/liu0909/aggbug/290821.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liu0909/" target="_blank">扬帆出海</a> 2009-08-12 14:33 <a href="http://www.blogjava.net/liu0909/articles/290821.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>