我应该如何将原型初始化转换为 ES6
How should I convert prototype initialization into ES6
我正在尝试创建 Google 地图叠加视图。我在 ES5 中有这段代码告诉我在我的标记原型中初始化一个对象,如下所示:
MainMarker.prototype = new google.maps.OverlayView();
如何将其准确转换为 ES6?
对于继承,比如Child.prototype = Object.create(Parent.prototype)
,对于ES6中的this,我们可以这样写
class Child extends Parent {
constructor () {
super();
}
}
但是第一个是怎么来的呢?
I have this code here in ES5 telling me to initialize an object in my marker prototype like below:
MainMarker.prototype = new google.maps.OverlayView();
无论如何,这 never was the correct way in ES51,所以不要试图保留不良做法。
就去
class MainMarker extends google.maps.OverlayView { … }
1:在这种特定情况下,使用 new
或 Object.create
没有区别,API docs 明确指出“OverlayView
构造函数保证为空函数。”。 Google 可能在他们的示例中使用了前一种语法,因为它更向后兼容。
我正在尝试创建 Google 地图叠加视图。我在 ES5 中有这段代码告诉我在我的标记原型中初始化一个对象,如下所示:
MainMarker.prototype = new google.maps.OverlayView();
如何将其准确转换为 ES6?
对于继承,比如Child.prototype = Object.create(Parent.prototype)
,对于ES6中的this,我们可以这样写
class Child extends Parent {
constructor () {
super();
}
}
但是第一个是怎么来的呢?
I have this code here in ES5 telling me to initialize an object in my marker prototype like below:
MainMarker.prototype = new google.maps.OverlayView();
无论如何,这 never was the correct way in ES51,所以不要试图保留不良做法。
就去
class MainMarker extends google.maps.OverlayView { … }
1:在这种特定情况下,使用 new
或 Object.create
没有区别,API docs 明确指出“OverlayView
构造函数保证为空函数。”。 Google 可能在他们的示例中使用了前一种语法,因为它更向后兼容。