Well in my "polyfill", I did someting similare: I deleted the value to
see if it changed.
But there is always the case where the value is undefined and the case
where you can not delete the property that make it quite hard...

On Wed, Sep 7, 2011 at 2:56 PM, Asen Bozhilov <asen.bozhi...@gmail.com> wrote:
> Lasse Reichstein:
>
>> You can use either Object.getPrototypeOf or __proto__ (with a preference on
>> the other, because it's not as easily modified) to check:
>>    prop in object && !(prop in object.__proto__)
>> which is not same check as hasOwnProperty (if the property is both on the
>> object and also in its prototype chain), but might work in cinch.
>
> In general interesting solution. Unfortunately it should be mention
> that it won't work in case of shadowing property from the prototype
> chain.
>
>
> var obj = Object.create({foo: "Inherit"});
>
> obj.foo = "Own";
>
> "foo" in obj && !("foo" in obj.__proto__) //false
>
> If there is mutable `__proto__' he is able to truncate the prototype
> chain, check with `in` and then restore the state of the prototype
> chain.
>
> function hasOwnProp(o, p) {
>    var proto = o.__proto__,
>        res;
>
>    o.__proto__ = null;
>    res = p in o;
>    o.__proto__ = proto;
>
>    return res;
> }
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to