Skip to content

Instantly share code, notes, and snippets.

@madhoshyagnik
Created April 13, 2024 02:14
Show Gist options
  • Save madhoshyagnik/bcff2acfcfaaebae6d28bb9459994211 to your computer and use it in GitHub Desktop.
Save madhoshyagnik/bcff2acfcfaaebae6d28bb9459994211 to your computer and use it in GitHub Desktop.
//arrow functions DO NOT WORK inside an object, if arrow function is user the window context is set for that method
let user = {
name: 'crystel',
age: 30,
email: 'crystel@gmail.com',
location: 'berlin',
blogs: ['why mac and cheese rules', ['10 things to make with marmite']],
login: function(){
console.log('user logged in');
},
logout: function(){
console.log('the user is logged out')
},
logBlogs: function(){
console.log('this user has written following blogs');
this.blogs.forEach(blog => {
console.log(blog);
})
}
};
user.logBlogs();
user.login();
@madhoshyagnik
Copy link
Author

image
SHORTENING METHODS inside objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment