, чтобы сохранить свой прогресс
Eugen
23 сент. 2022 г., 3:11

Обсуждение задания "Remember to Set the Constructor Property when Changing the Prototype"

А какой смысл выкладывать уроки со сложными темами, в корявом автоматическом переводе? На freecodecamp не все понял, думал может здесь проясню о чем говорится в уроке, но увы..

function Bird(name) { this.name = name; //own property } let duck = new Bird("Donald"); Bird.prototype = { numLegs: 2, eat: function() { console.log("nom nom nom"); }, describe: function() { console.log("My name is " + this.name); } }; console.log(duck.constructor === Bird); // true console.log(duck.constructor === Object) // false console.log(duck instanceof Bird) //false


при таком коде возвращается true, false, false
На freecodecamp:
There is one crucial side effect of manually setting the prototype to a new object. It erases the constructor property! This property can be used to check which constructor function created the instance, but since the property has been overwritten, it now gives false results:
duck.constructor === Bird; duck.constructor === Object; duck instanceof Bird;
In order, these expressions would evaluate to false, true, and true.
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype
Подразумевался вышеидущий другой код? На самом уроке он не приводился, взял предыдущих уроков
>> А какой смысл выкладывать уроки со сложными темами, в корявом автоматическом переводе? На freecodecamp не все понял, думал может здесь проясню о чем говорится в уроке, но увы..

Время от времени я прохожу и перевожу их. Несколько разделов перевел полностью (Базовые HTML, CSS, JS и React). До этого раздела не добрался еще.
Доступ к проекту бесплатный. За все время только один донат был. Так что извините, что так. Доберусь как-нибудь, и этот раздел переведу.

Добавить комментарий