有人能让我理解为什么我在最后一行输出中未定义?
var protoRabbit = {
speak: function(line){
print_line(this.type+' says, '+this.line);
print_line(this.type+' says, '+line);
},
kill : function (){
console.log('killerRabbit is not killing');
}
};
var killerRabbit = Object.create(protoRabbit);
killerRabbit.type='killer';
killerRabbit.line='killer here';
killerRabbit.speak('killer rabbit here');
print_line(killerRabbit.kill());
在控制台上操作:
killer says, killer here
killer says, killer rabbit here
killerRabbit is not killing
undefined
为什么在我添加属性(kill函数到初始对象)时未定义?
P.S。
print_line
是我制作的自定义函数,它接受一个参数并将输出打印到控制台......