What is the difference between functions declared with const and functions declared without let or const and a function declared differently in ES6 class?
class App extends Component { submitFood = () =>{ // some code }
Why the above works fine, but the declaration below gives an error:
class App extends Component { const submitFood = () =>{ // some code }
First of all: none of the examples you cited are valid ES6. Grammar rules for ES6 classes allow you to allow method definitions within the class body. I.e.
class MyClass { method1() {} method2() {} }
The first example, however, uses the suggestion of class field suggestions . This sentence extends the existing grammar by defining form properties.
class MyClass { someProperty = value; }
, . :
class MyClass { constructor() { this.someProperty = value; } }
- , let const .
let
const
, .
const submitFood = () =>{ // some code }
(submitFood=() {}) , let const., submitFood() . ( ReferenceError).
(submitFood=() {})
submitFood()
Source: https://habr.com/ru/post/1688232/More articles:multiple insertion into a table using Apache Spark - hadoopOn gradle: 3.0.0, several files were found with an OS-independent path "META-INF / ASL2.0", - androidEntityFrameworkCore - Diagnostics "Connection was not closed. The current state of the connection is open." - .net-coreWhat makes a lie in aot build angular cli - Memory problem - angularJava Stream: split into two lists by logical predicate - javaBootstrap grid misaligned - html"Data cannot be read because it is missing" when decoding JSON in Swift - jsonError creating fakes with iTuple - .netIn UML class diagrams, are there specific differences between operations and constructors? - umlTrimming a MIDI File with AudioKit - iosAll Articles