Created
August 8, 2023 16:40
-
-
Save suhailgupta03/81592ef2c0fd8ee98238d6b4c15a152e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// // SPORTS is a class | |
// // cricket is an object (or an instance of this class) | |
// // tennis is an object (or an instance of this class) | |
// function Sports(name, totalPlayers) { | |
// this.game = name; | |
// this.totalP = totalPlayers; | |
// this.printTotalPlayers = function() { | |
// console.log(this.totalP); | |
// } | |
// } | |
// const cricket = new Sports("Cricket", 11); | |
// cricket.printTotalPlayers(); | |
// const tennis = new Sports("Tennis", 2); | |
// tennis.printTotalPlayers(); | |
class Sports { | |
constructor(name, totalPlayers) { | |
// console.log("Inside constructor") | |
this.game = name; | |
this.totalP = totalPlayers; | |
} | |
printTotalPlayers() { | |
console.log(this.totalP); | |
} | |
printGameName() { | |
console.log(this.game); | |
} | |
} | |
const cricket = new Sports("Cricket", 11); | |
// console.log(cricket) | |
cricket.printTotalPlayers() | |
const tennis = new Sports("Tennis", 2); | |
tennis.printTotalPlayers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// // SPORTS is a class
// // cricket is an object (or an instance of this class)
// // tennis is an object (or an instance of this class)
// function Sports(name, totalPlayers) {
// this.game = name;
// this.totalP = totalPlayers;
// this.printTotalPlayers = function() {
// console.log(this.totalP);
// }
// }
// const cricket = new Sports("Cricket", 11);
// cricket.printTotalPlayers();
// const tennis = new Sports("Tennis", 2);
// tennis.printTotalPlayers();
class Sports {
constructor(gameName, totalPlayers){
this.game = gameName;
this.totalP = totalPlayers;
} // this is basically a PROXY for cricket object
// or a PROXY for tennis object
// whatever object is created using this class
}
const cricket = new Sports("Cricket", 11);
// console.log(cricket)
cricket.printTotalPlayers()
const tennis = new Sports("Tennis", 2);
tennis.printTotalPlayers();