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

Popular posts from this blog

php - Wordpress: Link a post to posts of another category manually -

javascript - Complete OpenIDConnect auth when requesting via Ajax -

apache - PHP Soap issue while content length is larger -