javascript - 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.
解决方案
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?
推荐阅读
- databricks - 我可以强制刷新 Databricks Delta 表,以便磁盘副本具有最新/一致的数据吗?
- eclipse - cucumber.runtime.CucumberException: java.lang.NullPointerException
- vert.x - 使用 Vert.x-redis 和 Quarkus 构建本机映像的问题
- c# - C# UWP 如何更改 TextBox 的前景
- python-3.x - 如何将列表与文件名匹配,然后将匹配的文件移动到 Python 中的新目录?
- c# - SQLite DB:使用 LINQ 创建一个 SQL 语句,该语句使用同一个表两次但没有 CROSS JOIN
- ruby-on-rails - 我如何在 Rails(Web Scraping)中写出永无止境的工作?
- java - 使用充气城堡从证书中提取 keyUsage 扩展
- azure-cosmosdb - json文档中的key可以在Cosmos Db中压缩吗
- c# - 使用 RunAndCollect 而不是 RunAndSave 时出现 CLR 错误