Js attribute Detection
var obj = {
'X': 'xxx', 'y': 2}; var yz = obj & obj. k & obj. k. z; // in this way, no error is reported. If no definition is defined, the undefinedconsole is returned. log (yz); // undefinedyz = obj & obj. x; console. log (yz); // xxx
HasOwnProperty () does not include the attributes of the prototype chain. in case of for loop enumeration, it depends on whether PropertyIsEnumerable () can be enumerated (), getOwnPropertyDescriptor () is a good method.
Var obj = {'X': 'xxx', 'y': 2}; console. log ('x' in obj); // trueconsole. log ('tostring' in obj); // trueconsole. log (obj. hasOwnProperty ('x'); // trueconsole. log (obj. hasOwnProperty ('tostring'); // falseconsole. log (obj. propertyIsEnumerable ('x'); // trueconsole. log (obj. propertyIsEnumerable ('tostring'); // falseObject. defineProperty (obj, 'z', {enumerable: false, value: 'zzz'}); for (var item in obj) {console. log ('item --- '+ item); // x y (because other properties on the prototype chain cannot be enumerated, only x y is output)} console. log ('Z' in obj );
Console. log (Object. getOwnPropertyDescriptor (obj, 'x'); // you can check the labels in this descriptor.