Biomehanika
Biomehanika

Reputation: 1540

Why the for...in statement returns both methods and properties?

As MDN says, the for...in statement has access to all properties (and values) related to an object.

I am not sure about why are methods also listed with this statement: if I loop on the document object I get not only the properties list related to it, but also the methods such as prompt() or focus()

Why are these methods named as "properties" on all documentation related to the for...in loop?

Upvotes: 0

Views: 51

Answers (2)

Serign Modou Bah
Serign Modou Bah

Reputation: 73

Please check this link, i think it will be helpful:https://msdn.microsoft.com/en-us/library/ms229054(v=vs.100).aspx...

Upvotes: 1

Koshinae
Koshinae

Reputation: 2320

Because methods are also properties, just with the type of function.

See for yourself:

for (var prop in document) {
    console.log("document." + prop + " = " + document[prop], typeof(document[prop]));
}

Upvotes: 2

Related Questions