如何检查唐老鸭在“function inTheForest(object)”中是否有名称,并且如果它不显示警报(“未找到名称”),然后继续显示约翰人的警报?
function Duck() {}
Duck.prototype.quack = function() {alert('Quaaaaaack!');};
Duck.prototype.feathers = function() {alert('The duck has white and gray feathers.');};
//Duck.prototype.name = function() {alert('Donald Duck');};
function Person() {}
Person.prototype.quack = function() {alert('The person imitates a duck.');};
Person.prototype.feathers = function() {alert('The person takes a feather from the ground and shows it.');};
Person.prototype.name = function() {alert('Rick James');};
function inTheForest(object) {
object.quack();
object.feathers();
object.name();
}
function game() {
var donald = new Duck();
var john = new Person();
inTheForest(donald);
inTheForest(john);
}
game();
最佳答案
关于javascript - 当关联函数中的原型(prototype)值丢失时,函数会中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34430228/