3

I don't see any syntactic difference between an ordinary function, and one which behaves like a constructor for a class. So are they the same?

Does this mean that every single function we define has a property named 'prototype' by default?

Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69

2 Answers2

2

Yes, every function has a property named prototype by default. The "construction" functionality is provided by the [[Construct]] internal property(invoked by new F()), which is set for every created function(see http://es5.github.io/#x13.2 - creating function objects, p18)

Sacho
  • 2,169
  • 1
  • 14
  • 13
0

Functions in JS have default property prototype, so to your question - yes.

But its very confusing to use it as a class structure within your code. I'd suggest you to check TypeScript language

Class hierarchy is similar to C#'s and compiler is compiling TypeScript code to confusing JavaScript for you :-)