top | item 41805658

(no title)

jknutson | 1 year ago

3 ways to declare functions? I am probably blanking but I can only think of:

``` function foo () {} const foo = () => {} ```

discuss

order

renlo|1 year ago

    function x() {/* ... */}
    const x = function() {/* ... */}
    const x = function foo() {/* ... */}
    const x = (function() {/* ... */}).bind(this)
    const x = (function foo() {/* ... */}).bind(this)
    const x = () => {/* ... */}
    const x = () => /* ... */

afiori|1 year ago

Apart from hoisting (which has little to do with functions directly) and `this` these are all equivalent

taosx|1 year ago

Not sure if it counts but there is `new Function("return x;")`

lelanthran|1 year ago

Doesn't `function* ()` count?

After all, you can add a `*` to any existing function without a change in the function or its callers.

wvenable|1 year ago

4 ways

onsclom|1 year ago

`const foo = function() {}`

mr_toad|1 year ago

Do function expressions count?

kevlened|1 year ago

const x = { foo() {} }