question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Singleton VS new Object

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
usama33commented, Jun 9, 2018

@jaggedsoft here is the diff of what I did. Let me know If you are unable to implement this.

https://www.diffchecker.com/cYkDMgwX

1reaction
bminocommented, Jul 14, 2018

I submitted PR #252 to address the issues of shared variables between singletons.

Testing:

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found