我承認知道小javascript,jquery或oop,但我知道足夠的東西在一起,有時讓他們工作。但是,這已經超出了我的頭腦,儘管我的谷歌我無法做出正面或負面的事情。這是我的代碼的要點:在同一類別的另一種方法中調用一個方法
jQuery(document).ready(function($) {
var methods = {
init : function(options) {
if (somthing) {
this.latlng(input);// <--- ERROR: Object has no method
}
},
auto : function() {
if (something) {
this.latlng(input);
} else {
this.location(input);
}
},
location : function (input) {
// draw map
},
latlng : function (input, l) {
// draw map
}
}
$.fn.codeAddress = function(method) {
// Method calling logic
if (methods[method]) {
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.tooltip');
}
};
var geo = new $(document).codeAddress(); // Initialize the object
});
我靠jQuery的文檔Plugin/Authoring爲我的模板,並開始從那裏piecemealing。理想情況下,它在文檔準備就緒時加載它自己的init(),但它不會將第二行加到最後一行來初始化對象。
映射最初是在init()中使用方法latlng()繪製的。這就是我在第6行得到錯誤的地方,this.latlng(input)Uncaught TypeError:Object [object Object] has no method'latlng'。此後,onclick事件處理程序調用auto()根據它接收到的輸入重繪地圖。
我很抱歉,如果我的解釋和/或代碼是垃圾表演。我一直在努力學習。
@adeneo,OP已經明確表示他對JavaScript不太瞭解。很好;) – Codasaurus