discussion about some improvements in semantic of some functions

discussion about some improvements in semantic of some functions


Hi,
As John requested I repeat the suggestions for the future of some functions
here hoping for coments.
text()
------
Should return an array with all texts of the nodes in the jQuery object. The
current behaviour can be easily simulated by $('.asdf').text().join('').
Drawback:
Current code in plugins and pages needs to be changed, though the change is
rather small.
Benefit:
A single text can be accessed as well:
    $('.asdf').text()[42];
the texts can be joined differently as well:
    '['+$('.asdf').text().join('][')+']';
attr('...')
-----------
Should return an array with all attributes of that name from all nodes in the
jQuery object. The current behaviour can be simulated by
$('.asdf').attr('name')[0].
Drawback:
Existing code must be changed slightly.
Benefit:
Access to all attribute values other than the first:
    $('.asdf').attr('name')[42];
Attribute values can be joined, sorted, whatever.
    $('.asdf').attr('name').sort();
is('...') and not('...')
------------------------
Should return an array of boolean values. The current behaviour can be
simulated by $('.asdf').is('img')[0] and $('.asdf').not('img')[0].
Drawback:
Again exsting code must be changed sightly.
Benefit:
Check for a speciffic value other than the first:
    $('.asdf').is('img')[42];
Helper functions with various boolean operators can be created:
    $.fn.has = function(selector) {
        var rval = false;
        $.each(this.is(selector), function(i,n) { rval = rval || n; });
        return rval;
    }
    $.fn.isEvery = function(selector) {
        var rval = false;
        $.each(this.is(selector), function(i,n) { rval = rval && n; });
        return rval;
    }
There are more functions like this. e.g. html(), val(), css(name), offset(),
height() and width(). They all operate on an array like object, the jQuery
Object, but return values from only one fixed object in that array. All of
them are more flexible when they return arrays. As for the three I have
picked, the simulation of the current behaviour is allways very easy.
Christof