Aral Balkan on Nostr: Oh my goodness, how did I miss that in ES7 you can use a closure as a method. Goodbye ...
Oh my goodness, how did I miss that in ES7 you can use a closure as a method. Goodbye `bind()`, you will not be missed :)
e.g.,
```js
class A {
b = () => console.log(this)
}
const a = new A()
a.b() // A { b: [Function: b] }
const c = a.b
c() // A { b: [Function:b] }
```
Nice! :)
#JavaScript #EcmaScript7 #ES7 #closures #classes #methods #bind #functions
Published at
2025-01-09 17:29:55Event JSON
{
"id": "fad2653e32b44ea51ad5afbe5f62435cca518ce0b2194f6a7c7c3a731a43e337",
"pubkey": "9da994565b2f3100ad1714080d081a90c771b9bb1276d939795f5a9e179af829",
"created_at": 1736443795,
"kind": 1,
"tags": [
[
"t",
"javascript"
],
[
"t",
"ecmascript7"
],
[
"t",
"es7"
],
[
"t",
"closures"
],
[
"t",
"classes"
],
[
"t",
"methods"
],
[
"t",
"bind"
],
[
"t",
"functions"
],
[
"proxy",
"https://mastodon.ar.al/users/aral/statuses/113799580584656650",
"activitypub"
]
],
"content": "Oh my goodness, how did I miss that in ES7 you can use a closure as a method. Goodbye `bind()`, you will not be missed :)\n\ne.g.,\n\n```js\nclass A {\n b = () =\u003e console.log(this)\n}\n\nconst a = new A()\na.b() // A { b: [Function: b] }\n\nconst c = a.b\nc() // A { b: [Function:b] }\n```\n\nNice! :)\n\n#JavaScript #EcmaScript7 #ES7 #closures #classes #methods #bind #functions",
"sig": "5266c95b9986518ec3a868736336afdfba94bcfa965aeae30c0a26a0719b0b5b450ef9b6b9e2b94654a4456cc5674fb225a86cfe920fa478b87480796d5a932a"
}