Sure that's the common explanation, but don't fall for it: globality has
everything to do with it. If the singleton didn't care about creating
global state, it could just have `this.created = true;` for its *only*
internal state and have thrown exceptions from the constructor for any
subsequent
I'm not 100% sure of your requirements, but this is what I assume you're
after:
-
file : soapClient.js
var memoizedClient;
var soap = require('soap');
var create = function (cb){
if (memoizedClient){
return cb(null, memoizedClient);
}
var
For example, if I have a module for emailing with a send() method on it,
I don't have it export a constructor; I have it export an object. That
object might maintain some state or it might not. When the module is
subsequently require()'d, it will have any state that it has accumulated
since.
this I get the jist of the conversation but my Javascript skills, less than
2 months, does not allow me to be able to code this up.
Also, as a starter in the new language the last thing I want to do is to
miss out on the language correct way of things and force lets say the Java
way of doing
I recommend being wary of any broad generalizations about programming
patterns :P
Rick
On Thu, Nov 21, 2013 at 7:13 AM, Gregg Caines cai...@gmail.com wrote:
The singleton pattern is actually unnecessary in most languages outside of
java, including javascript. You should be wary of any
Ok so this is the way i have it constructed... SoapClient is my module and
I want it to be used as a singleton, i.e. if it is initialized, it just
returns the connection, or SoapClient.instance...
var SoapClient = function() {
var soap = require('soap');
this.init = function (){
var url =
Aah, nevermind then, I misunerstood ;)
21 lis 2013 16:36 Gregg Caines gr...@caines.ca napisał(a):
Yeah... that's what I'm saying :)
G
On Thu, Nov 21, 2013 at 7:33 AM, Kamil Leszczuk kamit...@gmail.comwrote:
For example, if I have a module for emailing with a send() method on
it, I don't
Yeah... that's what I'm saying :)
G
On Thu, Nov 21, 2013 at 7:33 AM, Kamil Leszczuk kamit...@gmail.com wrote:
For example, if I have a module for emailing with a send() method on it,
I don't have it export a constructor; I have it export an object. That
object might maintain some state or
yeah that's right. You just need to add the line
module.exports = mySingleton
and in the caller file require as follows
var singleton = require('./single').mySingleton
Hope that helps
José
On Nov 19, 2013, at 2:40 AM, Reza Razavipour reza.razavip...@gmail.com wrote:
Wonderful book, thank you.