Well, the $() in prototype only accepts objects and strings (it may take
array's too, but I know that this code isn't utilising arrays).

So, the arg1 is only going to be an object or a string. I could check it's
type as object, but since I know those are the only possibilities being
passed, Im only worried about those two.



Blair McKenzie-2 wrote:
> 
> You're handling a case where arg1 isn't a string. What is the alternative?
> 
> Blair
> 
> On 1/12/07, Nate Cavanaugh <[EMAIL PROTECTED]> wrote:
>>
>>
>> John told me to post this here, so here it is....
>>
>> I am currently refactoring a large amount of code over to jQuery. Against
>> better principles, the HTML is rife with onclick="fn()", etc, so I am
>> having
>> to convert over the functions themselves.
>>
>> Prototype's $() will take a string or an object, just like jQuery does,
>> however, since prototype will ONLY look for id's if you pass it a string,
>> you do not have to include the #, whereas with jQuery, if you do not
>> include
>> the #, it will look for a tagname rather than an element by id.
>>
>> So, here is an example of a generic function currently:
>>
>> function test(arg1,arg2){
>> obj = $(arg1);
>> return obj;
>> }
>>
>> The above function will work in Prototype if it's a string or an object.
>>
>> So in my refactoring, I have been doing this:
>>
>> function test(arg1,arg2){
>> obj = (typeof arg1 == 'string') ? $('#'+arg1) : $(arg1);
>> return obj;
>> }
>>
>> Is this the best/only way?
>>
>> Anyone have any ideas?
>>
>> Thanks in advance!
>> --
>> View this message in context:
>> http://www.nabble.com/Refactoring-code-from-Prototype-%28-%24%28%29-type-ambiguity%29-tf2962817.html#a8289616
>> Sent from the JQuery mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Refactoring-code-from-Prototype-%28-%24%28%29-type-ambiguity%29-tf2962817.html#a8289872
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to