0

I'm currently studying javascript prototype and inheritance (man, it is confusing, but soldiering on)

function MyFunc(){}

I have noticed that there is a constructor property on both MyFunc and MyFunc.prototype

enter image description here

I know that MyFunc.prototype.constructor is pointing back to MyFunc, but I'm not exactly sure where Myfunc.constructor is pointing to?

So where does MyFunc.constructor is pointing to and what is its uses?

Thor
  • 9,638
  • 15
  • 62
  • 137
  • 4
    An object’s `constructor` property should point to its… constructor. `MyFunc` is a function, so its constructor is `Function`. – Ry- Mar 23 '17 at 01:23
  • The introductory statements of [`Function` on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) may clarify. – 4castle Mar 23 '17 at 01:26
  • correct me if I'm wrong, but I guess all function objects have its `constructor` property set to `Function`? – Thor Mar 23 '17 at 01:26
  • 1
    That's correct, but the use of the `Function` constructor is generally discouraged, for the same reasons that [`eval` is discouraged](http://stackoverflow.com/q/86513/5743988). – 4castle Mar 23 '17 at 01:30
  • 2
    http://stackoverflow.com/questions/35709103/if-functions-are-objects-in-javascript-why-the-function-constructor-points-to-f –  Mar 23 '17 at 01:30
  • 1
    “correct me if I'm wrong, but I guess all function objects have its `constructor` property set to `Function`?” Yes, unless you change it. (It’s a writable property.) – Ry- Mar 23 '17 at 01:31
  • 2
    Like all objects, Functions inherit from their internal `[[Prototype]]`, so function objects inherit the constructor property from [*Function.prototype*](http://www.ecma-international.org/ecma-262/7.0/index.html#sec-function.prototype). They do not have their own *constructor* property (though you can add one). – RobG Mar 23 '17 at 01:34

0 Answers0