-
-
Save shahab570/7807c5d61804983add284c14bb78795e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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