简体   繁体   English

什么是继承的可数属性?

[英]What are Inherited numerable properties?

I was reading the definition of for...in我正在阅读for...in的定义

The for...in statement iterates over all enumerable properties of objects that are keyed by strings (ignoring ones keyed by Symbols), including inherited enumerable properties. for...in语句遍历所有以字符串为键的对象的可枚举属性(忽略以符号为键的对象),包括继承的可枚举属性。

Now, I do understand what's a numerable property in JavaScript, but this term "inherited enumerable properties" is confusing, and I'm not able to understand it clearly.现在,我确实了解 JavaScript 中的可数属性是什么,但是“继承的可枚举属性”这个术语令人困惑,我无法清楚地理解它。

Example:例子:

 class A{ constructor(){ this.name="Sample" } } class B extends A{ constructor(){ super() this.planet="earth" } } let b=new B(); for(let props in b) console.log(props)

Explanation:解释:

A has property name . A具有属性名称 B is inheriting the class A . B继承了 class A So properties will also get inherited.所以属性也会被继承。

for(let props in objectOfClassB) will give you instance properties and its inherited properties. for(let props in objectOfClassB)将为您提供实例属性及其继承的属性。

Clear?清除?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM