Browse Source

Address: Return new instance if `this` isn't already instantiated.

patch-2
Braydon Fuller 10 years ago
parent
commit
deb54c5a20
  1. 5
      lib/address.js
  2. 1
      test/address.js

5
lib/address.js

@ -22,6 +22,10 @@ var Hash = require('./crypto/hash');
*/ */
function Address(data, network, type) { function Address(data, network, type) {
if (!(this instanceof Address)) {
return new Address(data, network, type);
}
if (!data) { if (!data) {
throw new TypeError('First argument is required, please include address data.'); throw new TypeError('First argument is required, please include address data.');
} }
@ -346,5 +350,4 @@ Address.prototype.inspect = function() {
return '<Address: ' + this.toString() + ', type: '+this.type+', network: '+this.network+'>'; return '<Address: ' + this.toString() + ', type: '+this.type+', network: '+this.network+'>';
} }
module.exports = Address; module.exports = Address;

1
test/address.js

@ -195,6 +195,7 @@ describe('Address', function() {
it('should make an address from a buffer', function() { it('should make an address from a buffer', function() {
var a = Address.fromBuffer(buf).toString().should.equal(str); var a = Address.fromBuffer(buf).toString().should.equal(str);
var b = new Address(buf).toString().should.equal(str); var b = new Address(buf).toString().should.equal(str);
var c = Address(buf).toString().should.equal(str);
}); });
it('should make an address from a string', function() { it('should make an address from a string', function() {

Loading…
Cancel
Save