function sayColor(sPrefix, sSuffix){ alert(sPrefix + this.color + sSuffix) } var obj = new Object(); obj.color = "red"; sayColor.call(obj, "the color is ", ", a ver nice color indeed.");
--------------------------------
function ClassA(sColor) { this.color = sColor; this.sayhaha = function() { alert(this.color); } } function ClassC(sColor) { ClassA.call(this, sColor);//当前的this为classc自身 } var classc = new ClassC("black"); alert(classc.color); classc.sayhaha();
var objA = new ClassA("red"); var objB = new ClassB("blue","Nicholas"); objA.saycolor(); objB.aaa(); objB.saycolor();//无法调用,因为是原型所以继承不到。 objB.sayName();