function Parent(args){ this.prop = args; } function Child(args){ Parent.call(this, args); } Child.prototype = Object.create(Parent.prototype); Child.prototype.constructor = Child; var child = new Child('test'); /** * 1) Куда сохраняется строка 'test' * при такой постановке? */ function Parent(args){ this.prop = args; } function Child(args){ Parent.call(this); this.prop = args; } Child.prototype = Object.create(Parent.prototype); Child.prototype.constructor = Child; var child = new Child('test'); /** * 2) Куда сохраняется строка 'test' * при такой постановке? */ function Test(args){ this.prop = args; // присваивая значение здесь } Test.prototype = { prop: undefined; // оно запишется сюда? Это вопрос 3. } var test = new Test('test'); - oneIn all cases, written to the appropriate instance. In # 3 you just set the default value through the prototype: jsbin.com/hamidahokihi/1/edit - RubaXa
- If we analyze the third question, then this.prop in the constructor refers to the property of the same name in the prototype? - vas
- Yes, but only until you have redefined it. - RubaXa
- Where did I redefine it? - vas
- oneNot exactly, just initially, until you defined this property, it referred to the value in the prototype. If it is very simple, you have a property in the prototype and a property in the instance, if you define it, if you delete it, it will again refer to the property in the prototype. - RubaXa
|