I'm working through some CodeWars katas and I would like to know: For what reason does this syntax work...
class SmallestIntegerFinder {
findSmallestInt(args) {
return Math.min(...args)
}
}
...but this other does not?
class SmallestIntegerFinder {
const findSmallestInt = args => Math.min(...args)
}
This is the error trace printed:
const findSmallestInt = args => Math.min(...args)
^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Object.<anonymous> ([eval]-wrapper:6:22)
at
at evalScript (bootstrap_node.js:353:27)
at run (bootstrap_node.js:122:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:121:9)
at bootstrap_node.js:504:3
I haven't had any problem using the second syntax in other katas, but this is the first time I use it inside a class, so I guess it has something to do with JavaScript classes that I haven't learnt yet or something else that is escaping me at the moment.
Thanks in advance!
classbody is not a block that could hold arbitrary statements?const … = …to work inside an object literal?