-2

I believe the below code is illegal in both ES6 and ES5.

const app = new Vue({router}).$mount('#app')

Since {router} is wrong, but this example is successfully executed here.

Can you help explain what syntax is this? What did I miss?

Nicolas S.Xu
  • 13,794
  • 31
  • 84
  • 129

1 Answers1

0

The pattern creates an object having the property of "routes" with value of array routes.

const routes = [
  { path: '/foo', component: "Foo" },
  { path: '/bar', component: "Bar" }
]

function props(prop) {
  console.log(prop)
}

props({routes});
guest271314
  • 1
  • 15
  • 104
  • 177
  • {routes} is object literal. It should be a key value pair (a:"1"). Why it only has one 'routes'? – Nicolas S.Xu Dec 06 '16 at 01:26
  • 1
    See [Destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), [How to make use of javascript built in arguments properly?](http://stackoverflow.com/questions/40297698/how-to-make-use-of-javascript-built-in-arguments-properly/40298741#40298741), [What is this called in javascript? ({name, value}) => ](http://stackoverflow.com/questions/40470272/what-is-this-called-in-javascript-name-value-span-span/40470289?s=4|0.0000#40470289) – guest271314 Dec 06 '16 at 01:30