Expected property shorthand
57 },
58 }
59 let token = jwt.sign({ payload }, secretKey, {
60 expiresIn: expiresIn, 61 });
62 return responseMsg(200, 'OK', 'User created successfully', token)
63 } catch (err) {
Expected property shorthand
106 },
107 }
108 let token = jwt.sign({ payload }, secretKey, {
109 expiresIn: expiresIn,110 });
111 return responseMsg(200, 'OK', 'User logged in successfully', token)
112 } catch (err) {
Expected property shorthand
45
46const start = async () => {
47 try {
48 await fastify.listen({ port: port })49 fastify.swagger()
50 } catch (err) {
51 console.log(err)
Description
ECMAScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.
Here are a few common examples using the ES5 syntax:
const x = 1, y = 2, z = 3;
// properties
const foo = {
x: x,
y: y,
z: z,
};
// methods
const foo = {
a: function() {},
b: function() {}
};
The ES6 equivalent syntax is::
// properties
const foo = {x, y, z};
// methods
const bar = {
a() { return 1 },
b() { return 2 }
};
NOTE: The shorthand properties are equivalent to function expressions.
Meaning that they do not bind their own this
inside their bodies.
It is still possible to access properties from the object inside a shorthand member function:
const object = {
x: 1,
getX() {
return this.x // valid
}
}
Bad Practice
const foo = {
bar: function () { return 1 }
};
Recommended
const foo = {
bar() { return 1 }
}