Skip to content

Instantly share code, notes, and snippets.

@gpDA
Created July 8, 2020 02:59
Show Gist options
  • Save gpDA/b3005cec655d95faf48a76a513ad784b to your computer and use it in GitHub Desktop.
Save gpDA/b3005cec655d95faf48a76a513ad784b to your computer and use it in GitHub Desktop.
function student(...args){
const inputArray = args // [ 'hello', 'world', 'people' ]
this.fname = inputArray[0];
if (inputArray.length === 3) {
this.mname = inputArray[1];
this.lname = inputArray[2];
} else {
this.mname = '';
this.lname = inputArray[1];
}
this.getFullName = function (){
return this.fname + " " + this.mname + " " + this.lname;
}
}
console.log(new student('gp', 'geonpyung', 'lee').getFullName()) // gp geonpyung lee
console.log(new student('gp', 'lee').getFullName()) // gp lee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment