Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 8, 2023 16:40
Show Gist options
  • Save suhailgupta03/81592ef2c0fd8ee98238d6b4c15a152e to your computer and use it in GitHub Desktop.
Save suhailgupta03/81592ef2c0fd8ee98238d6b4c15a152e to your computer and use it in GitHub Desktop.
// // 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();
@suhailgupta03
Copy link
Author

// // 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

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