options are differents. There is a trick which toggle Object.prototype
properties and addthem after.
It would cost two calls for each "for in" loop rather than N function calls
for each property:
var safeLoop = (function(){
var p = [];
return function(o){
// false after jQuery.noConflict()
if(window.$ === jQuery)
return o;
if(o){
for(var k in Object.prototype){
p.push(k, Object.prototype[k]);
delete Object.prototype[k];
};
return o;
} else {
for(var i = 0, length = p.length; i < length;)
Object.prototype[p[i++]] = p[i++];
p = [];
}
};
})();
// test case
function genericMethod(o){
for(var key in safeLoop(o))
alert(key);
safeLoop();
};
Object.prototype.test = "abc";
genericMethod({});
To test above code without jQuery we can simply use
function jQuery(); $ = jQuery;
the noConflict() method remove the dollar function shortcut from the global
object.
it is just an alternative, as other hundreds ...
On Tue, Apr 28, 2009 at 12:44 PM, DBJDBJ <[email protected]> wrote:
>
> To recap if I may ?
>
> The safer and slower approach is to use hasOwnProperty() in for .. in
> loops
> Even that is not 100% fool-proof (I like this term 'fool-proof' ;o) ,
> but improves situation considerably. Last and desperate "hand grenade"
> is :
>
> for ( var j in Object.prototype ) delete Object.prototype[j] ;
>
> (or whatever "awesome" trick code one wants to use ...)
>
> So the best way forward might be (as suggested) already
> jQuery.safe_and_slow.1.3.3.js for people who need to fight it out with
> legacy code before being able to revert to jquery.1.3.3.js ...
>
> So the question is : "oooza gona save us..?"
>
> -- DBJ
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---