var myObject = { };
Object.defineProperty(
myObject,"food",
{ enumerable: true, value: '燃面' }
);
Object.defineProperty(
myObject,"dessert",
{ enumerable: false, value: '大蛋糕' }
);
// 检查指定 property 是否可数
console.log(myObject.propertyIsEnumerable( "dessert" )) // false
console.log(myObject) // { food: "燃面" }
// 检查指定 property 在不在指定 object 内
console.log("dessert" in myObject); // true
console.log(myObject.hasOwnProperty( "dessert" )); // true
// 搜寻指定 object 内的所有 property key/name
console.log(Object.keys( myObject )); // ["food"]
console.log(Object.getOwnPropertyNames( myObject )); // ["food", "dessert"]
其中的(myObject.hasOwnProperty( "dessert" )
与 Object.keys( myObject )
以及 Object.getOwnPropertyNames(myObject)
都只会检查 myObject,不会检查到 Object prototype 层;不同於 in
operator 会完整检查。
祝大家健康开心~内容有出入都希望能多多提醒~感谢 ԅ(≖‿≖ԅ)
<<: Chapter4 - Canvas背景动画(III)风中的花朵 今天再加码让动画更加自然的方法
资讯安全管理制度运行过程中,会对即有的企业或机构文化带来一定的冲击。 顾问有教过、学员有学过都是真的...
前言 非同步概念的最後一小块拼图,要来学习怎麽使用 async/await async/await ...
Python 资料型态与变数等命名用法基本介绍,会先以w3schools 作为 run code t...
注:发文日和截图的日期不一定是同一天,所以价格计算上和当日不同,是很正常的。 买进 大同(2371)...
https://wolkesau.medium.com/python-语言-57370c0adcf7...