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

This commit is contained in:
Braydon Fuller 2014-11-24 15:43:00 -05:00
parent 9863b123c0
commit deb54c5a20
2 changed files with 5 additions and 1 deletions

View File

@ -22,6 +22,10 @@ var Hash = require('./crypto/hash');
*/
function Address(data, network, type) {
if (!(this instanceof Address)) {
return new Address(data, network, type);
}
if (!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+'>';
}
module.exports = Address;

View File

@ -195,6 +195,7 @@ describe('Address', function() {
it('should make an address from a buffer', function() {
var a = Address.fromBuffer(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() {