Dung Trinh
asked on
Javascript question
I am new to javascript and in one of my lecture, there is one question that I couldn't solve or understand how to solve it. I have to fill in the code in Sample in order to have a matching output. I tried to create
/*Output
Doe, John
Doe, John
Smith, Jane
Smith, Jane
*/
mostRecentSample = new Sample(first, last);
but it cause too much recursion error. Any suggestion? If you can come up with a solution, please explain why it workvar Sample = function(first, last) {
//code in here
};
var main = function() {
var sample = new Sample("John", "Doe");
sample.print();
if (Sample.mostRecent === sample)
{
print("In comparation");
Sample.mostRecent.print();
}
sample = new Sample("Jane", "Smith");
sample.print();
if (Sample.mostRecent === sample)
{
print("In comparation");
Sample.mostRecent.print();
}
};
main();
/*Output
Doe, John
Doe, John
Smith, Jane
Smith, Jane
*/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am taking a introduction to javascript class. I am using the book "Javascript, The Good part."