/*call1:
//将A对象的方法放在B对象上执行
*/
function ParentC()
{
this.Parent = "NOT-NULL";
}
function ChildC()
{
ParentC.call(this);
}
var c = new ChildC();
alert(c.Parent);
//NOT-NULL
/*call2:
//call3:继承
*/
function C3()
{
this.add = function(a, b)
{
return a + b;
}
}
function C4()
{
this.sub = function(a, b)
{
return a - b;
}
}
function C5()
{
C3.call(this);
C4.call(this);
}
var c5 = new C5();
//c5.add(5,2);//7
//c5.sub(5,2);//3
/* //js的call方法实现多重继承
*/
function A()
{
this.Name = "A";
this.SayHi = function()
{
alert(this.Name);
}
}
function B()
{
this.Name = "B";
this.Role = "PM";
this.show = function()
{
alert(this.Name + "-" + this.Role);
}
}
var a = new A();
var b = new B();
a.SayHi.call(b);
//alert("B");
转载于:https://www.cnblogs.com/nalanken/archive/2011/02/18/1957852.html