//摘自http://bbs.51js.com
<SCRIPT LANGUAGE="JavaScript">
<!--
function Base( v_sBaseName )
{
this.BaseName = v_sBaseName
this.BaseMethod = BaseMethod;
function BaseMethod( v_sStr )
{
alert("BaseName: " + this.BaseName + "\n" + "ExtendStr: " + v_sStr);
}
}
function Son( v_sName )
{
this.Name = v_sName
this.BaseName = this.Name;
this.Method = Method;
function Method( v_sStr )
{
alert("Name: " + this.Name + "\n" + "ExtendStr: " + v_sStr);
}
}
Son.prototype = new Base();
var O = new Son("初始化字串")
O.Method("Method附加字串");
O.BaseMethod("BaseMethod附加字串");
//-->
</SCRIPT>
SCRIPT LANGUAGE="JavaScript">
<!--
function Base( v_sBaseName )
{
this.BaseName = v_sBaseName
this.BaseMethod = BaseMethod;
function BaseMethod( v_sStr )
{
alert("BaseName: " + this.BaseName + "\n" + "ExtendStr: " + v_sStr);
}
}
function Son( v_sName )
{
Base.call(this, v_sName)
this.Name = v_sName
this.Method = Method;
function Method( v_sStr )
{
alert("Name: " + this.Name + "\n" + "ExtendStr: " + v_sStr);
}
}
var O = new Son("初始化字串")
O.Method("Method附加字串");
O.BaseMethod("BaseMethod附加字串");
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Base( v_sBaseName )
{
this.BaseName = v_sBaseName
this.BaseMethod = BaseMethod;
function BaseMethod( v_sStr )
{
alert("BaseName: " + this.BaseName + "\n" + "ExtendStr: " + v_sStr);
}
}
function Son( v_sName )
{
Base.call(this, v_sName)
this.base = new Base(v_sName) //建立一個基對象實例以便重載後可以調用基對象的函數
this.Name = v_sName
this.Method = Method;
function Method( v_sStr )
{
alert("Name: " + this.Name + "\n" + "ExtendStr: " + v_sStr);
}
this.BaseMethod = BaseMethod;
function BaseMethod( v_sStr )
{
alert("Override BaseName: " + this.BaseName + "\n" + "Override ExtendStr: " + v_sStr);
}
}
var O = new Son("初始化字串")
O.Method("Method附加字串");
O.BaseMethod("重載後的BaseMethod附加字串");
O.base.BaseMethod("BaseMethod附加字串");
//-->
</SCRIPT>
<script>
String.prototype.defaultText="这是String对象的默认值,也是一个静态属性";
var sss=new String();
alert(sss.defaultText);//任何字符传都有这个属性了
alert("所有的字符串都会有defaultText这个默认值属性:"+"所有的字符串都会有defaultText这个默认值属性".defaultText)
function b()
{
alert(String.prototype.defaultText);
b1.style.display="block";
}
function a()
{
delete String.prototype.defaultText;
}
</script>
<button onclick="b()">显示String对象的defaultText属性</button>
<button id=b1 style="display:none" onclick="a()">删掉String对象的defaultText属性</button>