function base()
{
.....
}
base.prototype.init=function(Name, Value)
{
this.Name=Name
this.Value=Value
}
.....
function Child(....)
{
this.init(...)
}
Child.prototype=new base
{
.....
}
base.prototype.init=function(Name, Value)
{
this.Name=Name
this.Value=Value
}
.....
function Child(....)
{
this.init(...)
}
Child.prototype=new base
也就意味着初始化一个Base类需要两句话:var oBase = new Base();
oBase.init('name', 'value');
有无办法可使Base类也可以以一句话来初始化?
var oBase = new Base('name', 'value');
function Base(Name, Value)
{
this.Name = Name;
this.Value = Value;
}function Child(Name, Value, Type)
{
this.Base('p','o');
}
Child.prototype.Base = Base;
var aa= new Child('p','o','i');
</script>
function Base(Name, Value)
{
this.Name = Name;
this.Value = Value;
}function Child(Name, Value, Type)
{
this.Base(Name,Value);
}
Child.prototype.Base = Base;
var aa= new Child('p','o','i');
</script>
马上给分.顺便问一下, 请问你从哪里找到this.Base(Name,Value)这条语句的用法的,如有网址,可否告诉链接.如有书,可否告诉书名?呵呵,我喜欢寻根刨底.
<html>
<head>
<title>Enter the title of your HTML document here</title>
</head>
<script language="javascript">
function Base(Name, Value)
{
this.Name = Name;
this.Value = Value;
}function Child(Name, Value, Type)
{
this.Base(Name,Value);
this.Type = Type;
}
Child.prototype.Base = Base;function Child1(Name, Value, Type, Message)
{
this.Child(Name, Value, Type);
}
var aa = new Base('p','o');
var bb = new Child('p', 'o', 'i');
var cc = new Child1('p', 'o', 'i', 'm');
</script>
<body>
<p>Enter the body text of your HTML document here</p>
</body>
</html>
<html>
<head>
<title>Enter the title of your HTML document here</title>
</head>
<script language="javascript">
function Base(Name, Value)
{
this.Name = Name;
this.Value = Value;
}function Child(Name, Value, Type)
{
this.Base(Name,Value);
this.Type = Type;
}
Child.prototype.Base = Base;function Child1(Name, Value, Type, Message)
{
this.Child(Name, Value, Type);
}
Child1.prototype.Child = Child;
var aa = new Base('p','o');
var bb = new Child('p', 'o', 'i');
var cc = new Child1('p', 'o', 'i', 'm');
</script>
<body>
<p>Enter the body text of your HTML document here</p>
</body>
</html>