Can'’t you just use myElem.adopt(elema, elemb, elemc);? I think it skips
null/false ‘elements’.


On Tue, Mar 30, 2010 at 11:58 AM, Barry van Oudtshoorn <
[email protected]> wrote:

>  Well, writing
>
> myElem.conditionalAdopt(elema, elemb, elemc);
>
> is a couple of characters shorter than writing
>
> if (elema) {
>   myElem.grab(elema);
> }
> if (elemb) {
>   myElem.grab(elemb);
> }
> if (elemc) {
>   myElem.grab(elemc);
> }
>
> (even when minified), so if you use this pattern a lot, it could pay off.
> :)
>
>
> Pragmatically, to reduce DOM manipulation, wouldn't this implementation of
> the function be somewhat more efficient:
>
> Element.implement({
>   conditionalAdopt: function() {
>     var els = [];
>     $A(arguments).each(function(item) {
>       item = document.id(item);
>       if (item) els.push(item);
>     }
>     return this.adopt(els);
>   }
> });
>
>
> On 30/03/2010 5:23 PM, Oskar Krawczyk wrote:
>
>  ... on the web where every byte counts.
>>
>
>  Haven't heard anyone saying that since 1999 - you know, 56K modems and
> all :-)
>
>
>> 2010/3/29 jacob <[email protected]>
>>
>> Anyone ever implemented something like this? or have a nicer way of
>>> doing it?
>>>
>>> http://mootools.net/shell/KPPNg/
>>>
>>> Element.implement({
>>>
>>>    conditionalAdopt: function(){
>>>        if(Array.prototype.splice.apply(arguments,[0,1])[0]){
>>>            Array.flatten(arguments).each(function(element){
>>>                element = document.id(element, true);
>>>                if (element) this.appendChild(element);
>>>            }, this);
>>>            return this;
>>>        }
>>>        return this;
>>>    }
>>>
>>> });
>>
>>


-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to