Singleton VS new Object
See original GitHub issueHi,
I just realized that api is singleton. What If user wants to create multiple binance api objects based on different api key/secrets? I did few changes and it works now with ‘new’. If you want I can create a pull request for you or following is what I did;
Replaced this;
module.exports = function() {
with
function Binance() { if (!(this instanceof Binance)) { return new Binance(); }
And added
module.exports = Binance;
Usage
var Binance = require('node-binance-api');
module.exports = class MyWrapper {
constructor() { this.binance = new Binance(); }
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:18 (12 by maintainers)
Top Results From Across the Web
new class instance vs Singleton class vs static method
There's no ultimately right answer to your question. And no need to look for the one. Actually what one should understand while designing ......
Read more >Idiomatic Kotlin: Object and Singleton | by Tompee Balauag
An object in Kotlin (among its many purposes) is both a class definition and an instantiation of single instance combined.
Read more >Singleton Class in Java - GeeksforGeeks
In object-oriented programming, a singleton class is a class that can have only one object (an instance of the class) at a time....
Read more >Difference Between Classes and Singleton Objects in Kotlin
In this quick tutorial, we're going to shed some light on the difference between classes and objects in the Kotlin programming language.
Read more >Singletons And Shared Instances - Alain Schlesser
The problem with a Singleton is not that it is shared, but that it enforces its own instantiation. · The Singleton pattern breaks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jaggedsoft here is the diff of what I did. Let me know If you are unable to implement this.
https://www.diffchecker.com/cYkDMgwX
I submitted PR #252 to address the issues of shared variables between singletons.
Testing: