Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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>Advertisements