Функция end() в jQuery возвращает элемент, установленный до того, что было до последнего деструктивного изменения, поэтому я могу видеть, как он должен использоваться, но я видел несколько примеров кода, например: на alistapart(вероятно, из более старых версий jQuery - статья от 2006 г.), который завершал каждый оператор с помощью .end(). например:
$( 'form.cmxform' ).hide().end();

Этот end() ничего не делает. Нет смысла так кодить. Он вернет $('#myBox') - пример довольно скудный. Интереснее выглядит примерно так:
$('#myBox').show ().children ('.myClass').hide ().end ().blink ();
Что покажет myBox, скроет указанные дочерние элементы, а затем моргнет окошко. Здесь есть более интересные примеры:
http://simonwillison.net/2007/Aug/15/jquery/
такие как:
$('form#login')
// hide all the labels inside the form with the 'optional' class
.find('label.optional').hide().end()
// add a red border to any password fields in the form
.find('input:password').css('border', '1px solid red').end()
// add a submit handler to the form
.submit(function(){
return confirm('Are you sure you want to submit?');
});
да, это то, что я подумал ... это в точности тот код, который я получил от alistapart (alistapart.com/articles/prettyaccessibleforms). ALA обычно довольно хорошо владеет своими приемами, поэтому мне было интересно, что-то мне не хватало.
Из jquery doc есть пример:
$('ul.first').find('.foo')
.css('background-color', 'red')
.end().find('.bar')
.css('background-color', 'green')
.end();
и после него уточнение:
The last end() is unnecessary, as we are discarding the jQuery object immediately thereafter. However, when the code is written in this form, the end() provides visual symmetry and a sense of completion —making the program, at least to the eyes of some developers, more readable, at the cost of a slight hit to performance as it is an additional function call.
о да, я имею в виду, я понимаю, что его использование, мне просто интересно, были ли какие-то аргументы за кодом, как в примере.