I'm a JS newbie and I've been playing around the object creation and cloning with create () and assign () when I encountered the following error:
let Student = {
first_name : '',
last_name : '',
major : '',
IsNotSet : function () {
return (this.first_name == '')
&& (this.last_name == '')
&& (this.major == '');
},
PrintDetails : function () {
if (this.IsNotSet ()) {
console.log ('Student is not set. Information cannot be retrieved.');
} else {
console.log ('Student Information:'
+ '\nFirst Name: ' + this.first_name
+ '\nLast Name: ' + this.last_name
+ '\nMajor: ' + this.major
);
}
}
};
let StudentWithMinor = Object.assign ({}, Student,
{
minor : '',
IsNotSet : function () {
return (Student.IsNotSet.bind (this))() && (this.minor == '');
},
PrintDetails : function () {
(Student.PrintDetails.bind (this))();
if (!this.IsNotSet ()) {
console.log ('Minor: ' + this.minor);
}
}
}
);
let first_student = Object.create (Student);
first_student.first_name = 'Andrea';
first_student.last_name = 'Chipenko';
first_student.major = 'B.S.E Computer Engineering';
first_student.PrintDetails ();
let second_student = Object.assign ({}, Student);
second_student.first_name = 'Enzo';
second_student.last_name = 'D\'Napolitano';
second_student.major = 'B.S. Computer Science';
second_student.PrintDetails ();
let third_student = Object.create (StudentWithMinor);
third_student.first_name = 'Kumar';
third_student.last_name = 'Patel';
third_student.major = 'B.A. Business Administration';
third_student.minor = 'Criminal Justice';
third_student.PrintDetails ();
let fourth_student = Object.assign ({}, third_student);
// The following line is problematic
fourth_student.PrintDetails ();
I am not very sure as to why the last line would error out. Can any experts out there perhaps give me an insight as to what is happening internally?
Thanks you so much in advance!