Skip to content

Commit d848f0f

Browse files
[refactor] Remove any reference to the global variable (#103)
Related #99
1 parent 3bc16f5 commit d848f0f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/browser.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var after = require('after');
99
var utf8 = require('./utf8');
1010

1111
var base64encoder;
12-
if (global && global.ArrayBuffer) {
12+
if (typeof ArrayBuffer !== 'undefined') {
1313
base64encoder = require('base64-arraybuffer');
1414
}
1515

@@ -101,9 +101,9 @@ exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
101101
? undefined
102102
: packet.data.buffer || packet.data;
103103

104-
if (global.ArrayBuffer && data instanceof ArrayBuffer) {
104+
if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) {
105105
return encodeArrayBuffer(packet, supportsBinary, callback);
106-
} else if (Blob && data instanceof global.Blob) {
106+
} else if (typeof Blob !== 'undefined' && data instanceof Blob) {
107107
return encodeBlob(packet, supportsBinary, callback);
108108
}
109109

@@ -189,7 +189,7 @@ function encodeBlob(packet, supportsBinary, callback) {
189189

190190
exports.encodeBase64Packet = function(packet, callback) {
191191
var message = 'b' + exports.packets[packet.type];
192-
if (Blob && packet.data instanceof global.Blob) {
192+
if (typeof Blob !== 'undefined' && packet.data instanceof Blob) {
193193
var fr = new FileReader();
194194
fr.onload = function() {
195195
var b64 = fr.result.split(',')[1];
@@ -210,7 +210,7 @@ exports.encodeBase64Packet = function(packet, callback) {
210210
}
211211
b64data = String.fromCharCode.apply(null, basic);
212212
}
213-
message += global.btoa(b64data);
213+
message += btoa(b64data);
214214
return callback(message);
215215
};
216216

0 commit comments

Comments
 (0)