jQuery--- .hasOwnProperty 用法
阿新 • • 發佈:2018-05-15
con 是否 沒有 property jquer 原型 java nbsp prope
☆ obj.hasOwnProperty(‘prop‘): 是用來判斷一個對象是否有你給出名稱的屬性或對象。不過需要註意的是, 此方法無法檢查該對象的原型鏈中是否具有該屬性,該屬性必須是對象本身的一個成員。 <script type="text/javascript"> var obj = { a: 1, fn: function(){ }, c:{ d: 5 } }; console.log(obj.hasOwnProperty(‘a‘ )); //true console.log(obj.hasOwnProperty(‘fn‘ )); //true console.log(obj.hasOwnProperty(‘c‘ )); //true console.log(obj.c.hasOwnProperty(‘d‘)); //true console.log(obj.hasOwnProperty(‘d‘ )); //false, obj對象沒有d屬性 var str = new String(); console.log(str.hasOwnProperty(‘substring‘));//false console.log(String.prototype.hasOwnProperty(‘substring‘));//true </script>
jQuery--- .hasOwnProperty 用法