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?
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?
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)
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 :-)