Hi, I've thought about John's comment about trying to immunize jQuery against hostile enviroments, especially changes to Object.prototype. In that regard, whats wrong with the following code? I've tested in FF with Firebug, and for now assume thats its pure JavaScript and will therefore work in other browsers just as well (or not).
Object.tainted = function() { var i = 0; for (var key in {}) i++; return i != 0; }; Object.prototype.each = function(fn) { var tainted = Object.tainted(); for (var key in this) { if (!tainted || !Object.prototype[key]) { fn(key, this[key]); } } }; function Obj() { this.foo = "foo"; } Obj.prototype = { bar: "bar" }; var x = new Obj(); x.each(function(key, value) { console.log( key, value ); }); Its prints out "foo foo" and "bar bar", but not "each function()", as its supposed to. How is this applicable to jQuery? Consider moving the tainted()-check to jQuery.each. To check itself runs just once for a full iteration, and itself doesn't really do anything. The result is cached, so the overhead in an untainted enviroment for each iteration is a single boolean-check, which I assume is neglible. For tainted enviroments, there is the overhead of checking if that property is defined on Object.prototype. I'm sure I've missed one or more drawbacks to that approach. Once that is out the way, I'll try to run some performance tests. Though any help with benchmarking is highly welcome. Jörn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---