My job is to build a constructor with print and mostRecent but I don\'t know how
ID: 3570988 • Letter: M
Question
My job is to build a constructor with print and mostRecent but I don't know how to make mostRect equals to sample so it can print out for the second time
var Sample = function(first, last) {
this.first = first;
this.last = last;
this.print = function() {
print(this.last + ", " + this.first);
}
//this.mostRecent = Sample;
};
var main = function() {
var sample = new Sample("John", "Doe");
sample.print();
Sample.print();
if (Sample.mostRecent === sample) {
Sample.mostRecent.print();
}
sample = new Sample("Jane", "Smith");
sample.print();
if (Sample.mostRecent === sample) {
Sample.mostRecent.print();
}
};
main();
Explanation / Answer
var Sample = function(first, last) {
this.first = first;
this.last = last;
this.print = function() {
print(this.last + ", " + this.first);
}
this.mostRecent = this;
};
var main = function() {
var sample = new Sample("John", "Doe");
sample.print();
Sample.print();
if (Sample.mostRecent === sample) {
Sample.mostRecent.print();
}
sample = new Sample("Jane", "Smith");
sample.print();
if (Sample.mostRecent === sample) {
Sample.mostRecent.print();
}
};
main();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.