首页 > 解决方案 > What are Inherited numerable properties?

问题描述

I was reading the definition of 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.

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. B is inheriting the class A. So properties will also get inherited.

for(let props in objectOfClassB) will give you instance properties and its inherited properties.

Clear?


推荐阅读