在下面的例子中,我预计createProduct函数将被覆盖。但结果是错误。如何用JavaScript中的原型覆盖函数?
var AbstractFactory = function(){
this.createProduct = function(){
throw new Error("The createProduct() method has not been implemented.");
}
}
AbstractFactory.prototype.createProduct = function(){
console.log('The method has been overwriten successfully');
};
var factory = new AbstractFactory();
factory.createProduct();
'工厂'对象具有'createProduct'方法本身,它没有被覆盖。 – Bergi