の109ページ「JavaScriptデザインパターンの学習」には、私を混乱させるコードサンプルがあります。jqueryステートメント "var collection = jQuery([1]);"とは何ですか?平均?
jQuery.single = (function(o){
var collection = jQuery([1]); // <-- i want to ask this line
return function(element) {
// give collection the element
collection[0] = element;
// return the collection
return collection;
}
})();
機能の使用は、このようなものです:
$('div').on('click', function() {
var html = jQuery.single(this).next().html();
console.log(html);
});
更新:答えるため 感謝。私は76 bytes for faster jQuery
var collection = jQuery([1]); // Fill with 1 item, to make sure length === 1
は、今私は理解して著者ページから元のコードのソースをチェックアウト。彼がこのコードサンプルを引用したときに、この本の著者 "JavaScript Design Patternsの学習"がこのコメントを追加してくれることを願っています。
私は '[1]'という配列を関数に渡していると思います! – NINCOMPOOP
関連リンクを投稿すると簡単になります – bipen
ここを見てくださいhttp://james.padolsey.com/javascript/76-bytes-for-faster-jquery/ –