Understanding this custom hasPrototypeProperty function in JavaScript -
how function determine if property exists on prototype
?
function hasprototypeproperty(object, name){ return !object.hasownproperty(name) && (name in object); }
i confused 2 things:
what !
operator doing hasownproperty
method?
and while &&
seems saying (name in object)
has true well, kind of not sure...
i know hasownproperty
return true
if property exists on instance, read still checks prototype
, if so, for? seems strange thing if instance thing matters?
thanks in advance!
what ! operator doing hasownproperty method?
it's boolean not operator. doesn't method, result of call.
and while && seems saying (name in object) has true well, kind of not sure...
yes, that's does.
i know hasownproperty return true if property exists on instance, read still checks prototype, if so, for?
not, not check prototype. in
operator however.
so hasprototypeproperty
function return true
iff object
has no own property given name
, there possible inherited property name
on object
.
Comments
Post a Comment