도움이 되었습니까?

문제

Using the get in JavaScript to make getter function

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Use get keyword to make getter function.

Example

Following is the code −

const studentDetails =
{
   studentName: "David Miller",
   get studentName() {
      console.log('I am calling the getter method...')
   }
}
console.log(studentDetails.studentName);

To run the above program, you need to use the following command −

The output is as follows −

node fileName.js.

Here, my file name is demo221.js.

Output

The output is as follows −

PS C:\Users\Amit\JavaScript-code> node demo221.js
I am calling the getter method...
Undefined
raja
Published on 03-Oct-2020 17:41:36
Advertisements
도움이 되었습니까?
제휴하지 않습니다 Tutorialspoint
scroll top