☆ ?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 用法
原文地址:https://www.cnblogs.com/hahajava/p/9042876.html