Well, I just did this too - though not from Prototype but from my own $()
function that took a string or an object. All I really needed to do was
change my $(str) calls to $('#' + str), which I did via global
search-and-replace - searched for $(" and replaced it with $("# - worked
beautifully and I don't have to worry about intermediate functions. And
where $() returned an object, I didn't have to change anything (though I do
as I encounter them to use jquery syntax rather than my own).

James


Nate Cavanaugh 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#a8290090
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to