Address: Return new instance if this isn't already instantiated.
This commit is contained in:
parent
9863b123c0
commit
deb54c5a20
@ -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;
|
||||||
|
|||||||
@ -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…
Reference in New Issue
Block a user