Skip to content

Commit 039c631

Browse files
committed
better getInstance pattern
1 parent 0ff0a2d commit 039c631

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

amplitude.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ var Amplitude = function() {
123123

124124
Amplitude.prototype.getInstance = function(instance) {
125125
instance = instance || DEFAULT_INSTANCE;
126-
if (!this._instances.hasOwnProperty(instance)) {
127-
this._instances[instance] = new AmplitudeClient();
126+
var client = this._instances[instance];
127+
if (client === undefined) {
128+
client = new AmplitudeClient();
129+
this._instances[instance] = client;
128130
}
129-
return this._instances[instance];
131+
return client;
130132
};
131133

132134
Amplitude.prototype.Identify = Identify;

0 commit comments

Comments
 (0)