この StackOverflow の回答によると、jQuery.fn の意味は何ですか? の fn プロパティjQuery.fn.jquery
は、prototype プロパティのエイリアスです。これは、完全なコードが以下にあるこれら2つのメソッドで同じであると思います
$.fn.map = function()
と$.fn.tweets = function()
私の質問は、たとえば、 $.fn.tweets がプロトタイプを使用して tweets メソッドを作成する場合、このコードはそれを$('tweets').tweets
呼び出すでしょうか...
var $tweets = $('#tweets').tweets({
query: buildQuery(approxLocation),
template: '#tweet-template'
});
もしそうなら、どのようにそのメソッドをトリガーすることができますか. たとえば、ファイルの読み込み時に変数を作成するだけで、クエリなどの他のメソッドが内部にある関数がトリガーされますか? ご協力いただきありがとうございます
メソッドの完全なコード
$.fn.map = function(method) {
console.trace();
console.log(method);
if (method == 'getInstance') {
console.log("fn.map");
return this.data('map');
}
return this.each(function() {
var $this = $(this);
var map = $this.data('map');
if (map && MyMap.prototype[method]) {
map[method] (Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
var options = method;
$this.data('map', new MyMap( this, options ));
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.map' );
}
});
}
$.fn.tweets = function(method) {
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.tweets' );
}
}
それらのメソッドを呼び出す変数?
var $tweets = $('#tweets').tweets({
query: buildQuery(approxLocation),
template: '#tweet-template'
});
var $map = $('#map').map({
initialLocation: approxLocation,
radius: 1000,
locationChanged: function(location) {
$tweets.tweets('setQuery', buildQuery(location));
}
});