0

If we create a object Function or Object, the creation process put reference of prototype prop of Object or Function object to the prototype of the new object! or copy all the props in the Obj or Func prototype prop to as the props of the new object?

If it reference the prototype of Obj Func to new obj prototype prop, so if we change one of them prop then it is like we change all of the object created until now and later, get affected!

If it copy, so it mean it copy a lot of functionality for each object? redundancy!

So confused and many other related question so lets go step by step, maybe also the question is not correct ones.

Thanks in advance, please if there is other such discussion refer me to that so don't waste time.

ja0k0010
  • 7
  • 6
  • Same reference to the same object in different prototype chains https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain You can write a little test and show that changes in one affects the others even after you've instantiated them. Until you've tried this, this is not a good question for SO since SO is for actual problems with code – Ruan Mendes Oct 29 '18 at 13:25
  • Wow! That is a problem. You mean if I change for example toString for an object it will affect all my objects? i don't think so! Or the option is to provide a toString in the new object as prop of that? object.toString= instead of object.prototype.toString= ? but then, log or other func that use toString will use the object toString instead of prototype ones? – ja0k0010 Oct 29 '18 at 13:34
  • @JuanMendes I know this, I tried this. But I think it is nonsense both of them, as this is working now so my understanding is wrong. I need some clarification that it won't be gained through trial! That is, if all the prototype set to one thing then whenever we do some change it will affect all objects, it is not and shouldn't be true. – ja0k0010 Oct 30 '18 at 02:55
  • When we create a new object by syntax 'new (thatobjectfunction)' it will put Object prototype to its prototype or will put thatobjectfunction proto to new proto and then access Object proto also in a chain? I think it is the right way so we can have different standalone objects – ja0k0010 Oct 30 '18 at 02:58
  • You need to show some code if you want to post a question at StackOverflow. If you don't have a very specific code question, try https://softwareengineering.stackexchange.com/ Or see [my blog post explaining prototypal inheritance](http://js-bits.blogspot.com/2014/10/understanding-prototypical-inheritance.html) – Ruan Mendes Oct 30 '18 at 11:48
  • @JuanMendes I don't know why you think i am stupid person or lazy or just ask for nothing! btw, i read your article and all things you explain there is obvious to me. i am also computer scientist bachelor. I am just wonder about some behavior like when we change toString in the prototype prop of a simple object why not all other object toString affected! so there should be some trick in prototypal chain ... – ja0k0010 Oct 31 '18 at 10:24
  • @ja0k0010 Seems like you don't want my help. My post explains why changing toString of an object doesn't affect its prototype version and therefore other instances. Like I said before, at this forum we like questions with code, it's unclear what you are asking. We like very specific questions. – Ruan Mendes Oct 31 '18 at 12:01
  • @JuanMendes I need and like and appreciate your help. – ja0k0010 Nov 01 '18 at 10:26

1 Answers1

0

__proto__ VS. prototype in JavaScript

Confusion resolved based on these info

proto is different than prototype property. only function has prototype. proto in a object refer to a prototype of a function, most of the time the function that built that object.

The info in above link and diagram on it is the most you need to understand

ja0k0010
  • 7
  • 6