I saw a part of javascript code on MDN and I am wondering how to work below code and what does it mean ?
var obj = { get x() { return 17; } };
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I know the keyword
getjust classifiesx()as a getter, and appears to self-invoke. It’s not supported in jScript (IE) and it’s not a reserved word.You’d reference it like so:
obj.x; // 17In lamen’s terms, these will behave identically: