Skip to content

Instantly share code, notes, and snippets.

@shahab570
Last active January 7, 2021 13:58
Show Gist options
  • Save shahab570/7807c5d61804983add284c14bb78795e to your computer and use it in GitHub Desktop.
Save shahab570/7807c5d61804983add284c14bb78795e to your computer and use it in GitHub Desktop.
class Person {
//constructor is used to create and initialize obects created with class
//there can be only one construcotor inside a class
constructor(name, gender) {
this.name = name;
this.gender = gender;
}
getName() { // getName() is method definitons of the class
return this.name;
}
getGender() {
//It's another methdo definiton of the class
//As this is defined inside Person class,any object created with Person class can access this method.
return this.gender;
}
}
let Bob = new Person("Bob", "male");
console.log(Bob.getGender()); //male
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment