0
我正在尝试创建Google地图叠加视图。我在这里有这个代码在ES5告诉我要在我的标志原型初始化对象象下面这样:我应该如何将原型初始化转换为ES6
MainMarker.prototype = new google.maps.OverlayView();
如何准确地将它转换为ES6?
继承,如Child.prototype = Object.create(Parent.prototype)
,这在ES6,我们可以编写
class Child extends Parent {
constructor() {
super();
}
}
但如何来约与第一个?
我不明白'Child.prototype = Parent.prototype'与'Child.prototype = Object.create(Parent.prototype)'之间的区别,我相信'Object.create'会创建一个' Parent.prototype'但不初始化。在这种情况下,Child.prototype = new Parent(),它是不是初始化** Child的**原型对象? – cs1193
最佳做法与否,OP会特别询问ES5 – terpinmd
@ cs1193首先根本不会创建副本,只是使用相同的对象。 'Object.create()'确实创建了一个从参数继承的新对象。 'new Parent()'确实会初始化我们不想要的原型对象。另请参见[here](https://stackoverflow.com/a/17393153/1048572?Benefits-of-using-Object.create-for-inheritance)和[here](https://stackoverflow.com/questions/11088365/why-wouldnt-i-use-child-prototype-parent-prototype-rather-child-prototype-new-parent) – Bergi