JavaScript继承通过原型

mal*_*uri 2 javascript

有最流行的JavaScript继承方法:

function extend(Child, Parent) {
    var F = function() { }
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child.superclass = Parent.prototype;
}
Run Code Online (Sandbox Code Playgroud)

我现在正在学习JS,但是我有很多Java经验,这种继承模型对我来说似乎有些困难.为什么我不能做以下事情:

function extend(Child, Parent) {
    Child.prototype = Parent.prototype; 
    Child.prototype.constructor = Child;
}
Run Code Online (Sandbox Code Playgroud)

我想我不了解/了解一些事情,但在我看来,F对象毫无用处.请澄清一下情况.谢谢.

mea*_*gar 5

 Child.prototype = Parent.prototype; 
Run Code Online (Sandbox Code Playgroud)

现在Child.prototypeParent.prototype同一个对象.

添加方法Child.prototype将添加它们Parent.prototype,这不是经典OOP继承的工作方式.