- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use arrow functions used as methods in JavaScript?
Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly. Arrow functions are generally used for a non-method function. Let’s see how to use arrow functions used as methods:
Example
You can try to run the following code to implement arrow functions used as methods
<!DOCTYPE html> <html> <body> <script> 'use strict'; var ob1 = { val1: 75, val2: 100, x: () => document.write(this.val1, this), y: function() { document.write("<br>"+this.val1, this); }, z: function() { document.write("<br>"+this.val2, this); }, } ob1.x(); ob1.y(); ob1.z(); </script> </body> </html>
- Related Articles
- When you should not use JavaScript Arrow Functions?
- Arrow functions in Javascript
- Lambdas with Arrow Functions in JavaScriptLambdas with Arrow Functions in JavaScript
- Regular functions vs Arrow functions in JavaScript?
- Fat arrow functions in JavaScript
- Concise arrow functions in JavaScript
- Higher-Order Arrow Functions in JavaScript.
- Difference between regular functions and arrow functions in JavaScript
- Fat vs concise arrow functions in JavaScript
- How do I use strings to call functions/methods in Python?
- How to use named arguments in JavaScript functions?
- How to use Spread Syntax with arguments in JavaScript functions?
- When to use anonymous JavaScript functions?
- How to define an Arrow Function in JavaScript?
- Do you think JavaScript Functions are Object Methods?

Advertisements