1
我試圖創建一個自定義的JavaScript類從google.maps.Map(V3 API)繼承。 下面的代碼:不能在我的自定義類(JavaScript)的繼承google.maps.Map V3
function MyClass(domElem, options){
google.maps.Map.call(this, domElem, options);
var custom_var = new google.maps.MVCArray();
this.getCustomVar = function(){ return custom_var };
}
MyClass.prototype = new google.maps.Map;
MyClass.prototype.constructor = MyClass;
此代碼拋出一個控制檯錯誤,如:
Uncaught TypeError: Cannot read property 'offsetWidth' of undefined
我已經試圖把這個setTimeout的有5秒的延遲,但我認爲DOM元素不這個問題(因爲它在我使用純google.maps.Map構造函數進行操作時工作)。
謝謝...
沒有問題來自該行:MyClass.prototype = new google.maps.Map,因爲你沒有任何參數構造它? – philipp 2012-03-28 17:31:44
嗨philipp,我不這麼認爲,因爲我做了同樣的google.maps.Marker和google.maps.Polygon類,它的工作... – fernandosavio 2012-03-30 18:15:31