On Mar 28, 11:32 am, kangax <[EMAIL PROTECTED]> wrote:
> Isn't hasOwnProperty missing in Safari < 2.0.2 ?

Apparently, propertyIsEnumerable is an alternative but I think it's
missing from those versions too.

I probably should also mention that the only robust way to use for..in
is to implement object creation using a scheme where you know exactly
the propreties to include or ignore.  You might like to try this one
in Firefox and IE:

var t = {};
alert(
      t.hasOwnProperty('__proto__') + '\n' +
      t.hasOwnProperty('__parent__') + '\n' +
      '');

Perahps an alternative is to see if the property exists in an
unextended $A:

  var testArray = $A();
  for (var p in obj) {
    if (!(p in testArray)) {
      // p is not a property of $A
    }
  }

Another strategy is to modify Prototype.js so that all methods added
to Array.prototype also have a dontEnum property added that is set to
true, something like:

  Object.extend(Array.prototype, {
    _each: function(iterator) {
               ...
    },
    ...
    toJSON: function() {
               ...
    }
  });

  for (var p in Array.prototype) {
    Array.prototype[p].dontEnum = true;
  }

Which assumes all the additions are objects, which seems OK, and
then...

  for (var p in obj) {
    if (!obj[p].dontEnum) {
      ...
    }
  }

Noting that you can't actually make any property DontEnum using native
code.  The last approach is untested, feel free to criticise.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to