<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
//创建连接一个字符串父类
function StringBuffer()
{
//私有属性 _strings
this._strings= new Array;
}
//以下为StringBuffer类2个方法
StringBuffer.prototype.append = function (str)
{
this._strings.push(str);
}
StringBuffer.prototype.toString = function(){
return this._strings.join('');
}
//子类
function StringBufferA()
{
}
//继承父类所有属性与方法
StringBufferA.prototype = new StringBuffer();
//复写父类方法toString
StringBufferA.prototype.toString = function(type){
return this._strings.join(type);
}
//测试代码
function test()
{
//基类
var buffer = new StringBuffer();
buffer.append("Hello");
buffer.append("World");
var result = buffer.toString();
alert(result);
//继承类
var bufferA = new StringBufferA();
bufferA.append("Hello");
bufferA.append("World");
var resultA = bufferA.toString('--------');
alert(resultA);
}
window.οnlοad=test;
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>