【发布时间】:2017-05-04 20:13:54
【问题描述】:
我正在尝试从 google.maps.Map 对象扩展我的原型函数。但我得到了无法读取未定义的属性“firstChild”。
基本上我只想添加一个自定义原型对象,它也是 google.maps.Map 的一个实例 下面是我的代码
<script src="https://maps.googleapis.com/maps/api/js?key=MY_KEY&callback=initMap&libraries=drawing" async defer></script>
function Map(id, options) {
this.id = id;
this.latlng = options.center;
}
Map.prototype = new google.maps.Map;
function initMap()
{
map = new Map('map', mapOptions);
}
所以我喜欢的是当我运行 'new Map('map', mapOptions)' 这将创建一个新的 google.maps.Map();实例,这将呈现一个地图。但我不确定我在这里缺少什么,因为我对在 javascript 中使用原型还很陌生。希望你能帮我解决这个问题。谢谢
【问题讨论】:
标签: javascript google-maps prototype