Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the shortest JS function creation using a key of an object [closed]

Tags:

javascript

var o = {["k"](){}}; // {k: ƒ}
o.k();

Here you can see an example:

enter image description here

How {["k"](){}} is compiled to an object which has a key k inside which is a function?


1 Answers

{["k"](){}}

equals:

{
  k(){}
}

Which is ES2015 short method syntax for:

{
  k: function(){}
}
like image 116
Jonas Wilms Avatar answered Dec 14 '25 21:12

Jonas Wilms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!