5

I'm using Vuetify for a vue app, in this file I saw a very strange syntax which I can't find what it is

on line 38:

const data = {
    attrs: { disabled: this.disabled },
    class: this.classes,
    props: {},
    directives: [{
      name: 'ripple',
      value: this.ripple || false
    }],
    on: {
      ...(this.$listeners || {}),  // <<<---- here
      click: this.click
    }
  }

can anyone tell what is that three dots? any articles about this would be nice

thanks

Developerium
  • 6,563
  • 4
  • 30
  • 54

2 Answers2

6

That's the spread operator! It grabs all the properties from the object.

In that example, it'll copy the object without mutating it.

xavdid
  • 4,430
  • 2
  • 18
  • 29
3

it's a spread operator, which is used in ES6 for both objects and arrays in Javascript. Here, the returned value of (this.$listeners || {}) is extracted. This returned value, combined with click: this.click is added into another empty object, following the "on: "

Alison Z
  • 85
  • 1
  • 8