Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regular functions and not arrow functions in the index.js file of the modules. #2503

Closed
vladimiry opened this issue Mar 14, 2019 · 4 comments · Fixed by #2524
Closed
Labels
Bug Addressing a bug

Comments

@vladimiry
Copy link

https://github.com/ethereum/web3.js/blob/5023c450a783b892da862712e0d8dc26cddba4ab/packages/web3-eth/src/index.js#L76

https://github.com/ethereum/web3.js/blob/5023c450a783b892da862712e0d8dc26cddba4ab/packages/web3-eth/src/index.js#L87

In a clean not-transpiled environment such code will give you TransactionSigner is not a constructor error as arrow function cannot be acting as a class constructor::

class EthTransactionSigner {}

const TransactionSigner = () => {
    return new EthTransactionSigner();
};

new TransactionSigner()

worng-arrow-function-call

It's currently only working probably because Babel transpiles arrow functions to a regular/ES5 functions which can be acting as class constructors.

I'd suggest renaming TransactionSigner and MethodFactory to something like constructTransactionSigner and constructMethodFactory functions and then calling them without using new but as a regular function calls.

@nivida
Copy link
Contributor

nivida commented Mar 14, 2019

First I had such factory methods in each index.js but I've removed them because it would break the API for the standalone modules. This will get improved with the implementation of the Web3 Namespace.

Edit:
I'm using the same pattern also for internal classes to have a consistent way over all index.js files and yes it wouldn't work without babel.

@nivida nivida added the Enhancement Includes improvements or optimizations label Mar 14, 2019
@vladimiry
Copy link
Author

vladimiry commented Mar 14, 2019

Maybe then for the sake of explicitness simply using regular/ES5 functions as they can act as classes.

@nivida
Copy link
Contributor

nivida commented Mar 14, 2019

Yes, right I will improve this later. Currently, there are issues with a higher priority. :)

@nivida nivida changed the title Wrong "new TransactionSigner" and "new MethodFactory()" calls in web3-eth/src/index.js Use regular function and not arrow functions in the index.js filed of the modules. Mar 14, 2019
@nivida nivida changed the title Use regular function and not arrow functions in the index.js filed of the modules. Use regular functions and not arrow functions in the index.js filed of the modules. Mar 14, 2019
@nivida nivida changed the title Use regular functions and not arrow functions in the index.js filed of the modules. Use regular functions and not arrow functions in the index.js file of the modules. Mar 14, 2019
@nivida
Copy link
Contributor

nivida commented Mar 18, 2019

Changed this issue label to bug because it does not work with the arrow methods if you use a submodule module.
Thanks for figuring this out!

@nivida nivida added Bug Addressing a bug and removed Enhancement Includes improvements or optimizations labels Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants