Skip to content

Instantly share code, notes, and snippets.

@K-Vishwak
Last active May 5, 2024 13:01
Show Gist options
  • Save K-Vishwak/1f83ed55eefa8b06d6c517a57dd0011a to your computer and use it in GitHub Desktop.
Save K-Vishwak/1f83ed55eefa8b06d6c517a57dd0011a to your computer and use it in GitHub Desktop.
// Using normal functions.
class Point {
name= 'test';
constructor() {
}
getName() {
return this.name;
}
}
const p = new Point();
const obj = {
name: 'test1',
getName: p.getName
}
console.log(obj.getName());
// Using arrow functions.
class Point {
name= 'test';
constructor() {
}
getName = () => {
return this.name;
}
}
const p = new Point();
const obj = {
name: 'test1',
getName: p.getName
}
console.log(obj.getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment