You write the following JavaScript code. (Line numbers are included for reference only.)
You need to write a function that will initialize and encapsulate the member variable fullname.
Which are two possible code fragments that you can insert at line 02 to achieve the goal? Each correct answer presents a complete solution.
NOTE: Each correct selection is worth one point.
A. function Student(someName) { fullname=someName;
}
B. function Student (someName) { var fullname=someName;
}
C. function Student (fullname) {
This.fullname=fullname;
}
D. function Student (someName) { this.fullname=someName;
}
Question doesn’t make sense. Only correct answer is D.
A and B give undefined because you declare fullname as a variable and not an object property with ‘this’.
C gives an error because ‘This’ does not exist, but ‘this’ does.