Express + EJS - passing arguments to EJS view

∥☆過路亽.° 提交于 2019-12-05 21:51:41

The difference between the two is just how you're defining your object and its properties.

{ products } tells the V8 engine to assign the property products the value of the variable products that is in scope. This is called Object Literal Property Value Shorthand and is a feature of ES6.

{ products: products } is the long-form way to create an object in ES6 and the only way in any version prior to ES6.

As long as your Node version supports the shorthand you can use it. Its all about preference and readability, there is no right or wrong way here.

Both codes are cpmpiled to the same result. The first version is suggested by linter because it is shortener and readable.

Please learn JavaScript style guide, there are a lot of guides, e.g. airbnb, Google, etc.

I recommend airbnb here. https://github.com/airbnb/javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!