What are methods definitions in object literals and when to use them?

38 views Asked by At

If I have the following object literal, I understand that val and prop are properties of the obj object.

const obj = {
  val: 7,

  prop: function() {
    alert("prop " + this.val);
  },

  met() {
    alert("met " + this.val);
  }
};

obj.prop();
obj.met();

Property prop holds a reference to an anonymous function. Such a property is also referred to as a method.

In Visual Studio IntelliSense:

  • prop is referred to as property,
  • met is referred to as method.

But

  1. What is met?
  2. How does it differ from prop?
  3. When to use prop syntax and when met?
0

There are 0 answers