On Monday 09 March 2009 21:51:05 kangax wrote:
> > > It's possible that we'll introduce a custom `hasOwnProperty` in later
> > > revisions.
> >
> > Makes sense.
> > if( !hasOwnProperty )
> > hasOwnProperty = function hasOwnProperty(){ ... };
>
> I was thinking of something like:
>
> var hasOwnProperty = (function(){
> var hop = Object.prototype.hasOwnProperty;
> if (hop) {
> return function(obj, prop) {
> return hop.call(obj, prop);
> }
> }
Why not:
if( hop )
return hop;
Does hop need to be wrapped?
> return function(obj, prop) {
> if (obj) {
> var c = obj.constructor;
> if (c && c.prototype) {
> return obj[prop] !== c.prototype[prop];
> }
> }
> return null;
> }
> })();
>
> This fallback not bullet-proof, but should cover most of the cases.
Yep, the tragic case where something just happens to have a property in a
prototype *and* the same property directly - could happen! Still, I think the
code above would be fine for almost all cases.
--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---