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 hn newest 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 load replies (1) onsclom|1 year ago `const foo = function() {}` mr_toad|1 year ago Do function expressions count? kevlened|1 year ago const x = { foo() {} }
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
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 load replies (1)
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.
renlo|1 year ago
afiori|1 year ago
taosx|1 year ago
lelanthran|1 year ago
After all, you can add a `*` to any existing function without a change in the function or its callers.
wvenable|1 year ago
onsclom|1 year ago
mr_toad|1 year ago
kevlened|1 year ago