Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the hasOwnProperty attribute in js

Shulou Source: shulou.com Published: 2022-05-31 10:39:08 10月30日 Update

This article mainly explains "how to use hasOwnProperty attribute in js". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use hasOwnProperty attribute in js" together.

js does not protect hasOwnProperty from illegal use, if an object happens to have this property, you need to use the external hasOwnProperty function to get the correct result.

When checking whether an attribute exists on an object, hasOwnProperty is the only method available.

examples

var foo = { hasOwnProperty: function() { return false; }, bar: 'Here be dragons'}; foo.hasOwnProperty('bar');//always returns false//use hasOwnProperty of other objects, and set its context to foo({}).hasOwnProperty.call(foo, 'bar'); // true Thank you for reading, the above is the content of "how to use hasOwnProperty in js". After studying this article, I believe everyone has a deeper understanding of how to use hasOwnProperty in js. The specific usage needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Attributes objects learning content up and down context functions examples that is ideas situations articles methods more knowledge knowledge points articles results follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker vpn Apple Shulou Information