FlowCrypt / flowcrypt-browser

FlowCrypt Browser extension for Chrome and Firefox
https://flowcrypt.com
Other
373 stars 46 forks source link

forbid .bind and instead propose fat arrow method alternative #3205

Open tomholub opened 3 years ago

tomholub commented 3 years ago

I thought I have forbidden .bind with a linter, but it looks like I didn't. I'll make another issue.

_Originally posted by @tomholub in https://github.com/FlowCrypt/flowcrypt-browser/pull/3198#discussion_r532873258_

tomholub commented 3 years ago

Yes, actually in some other programming languages (C#) when you pass a reference to a method (opgpKey.getEncryptionKey) this reference actually includes this reference for the non-static method (opgpKey). For Javascript, I have to bind opgpKey explicitly so that getEncryptionKey will see it as this. Of course we can bind it via lambda like getEncryptionKey = (params) => opgpKey.getEncryptionKey(params) if you're more comfortable with this programming-style binding.