Skip to content

Commit 3618141

Browse files
committed
Use new toString for toJson
1 parent ae7c47e commit 3618141

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

snippets/mongocompat/mongotypes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,15 @@ if (typeof NumberDecimal !== 'undefined') {
443443
if (!NumberDecimal.prototype) {
444444
NumberDecimal.prototype = {};
445445
}
446-
NumberDecimal.prototype.nativeToString = NumberDecimal.prototype.toString
447-
448-
NumberDecimal.prototype.tojson = function() {
449-
return this.nativeToString();
450-
};
451446

447+
NumberDecimal.prototype.nativeToString = NumberDecimal.prototype.toString
452448
NumberDecimal.prototype.toString = function() {
453449
return `NumberDecimal("${this.nativeToString()}")`;
454450
};
451+
452+
NumberDecimal.prototype.tojson = function() {
453+
return this.toString();
454+
};
455455
}
456456

457457
// ObjectId

snippets/mongocompat/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ const nl2 = NumberLong("200");
2424
assert.strictEqual(maxLong.compare(nl2), 1);
2525
const decimal = NumberDecimal("1.1");
2626
assert.strictEqual(decimal.toString(), 'NumberDecimal("1.1")');
27-
assert.strictEqual(decimal.tojson(), '1.1');
27+
assert.strictEqual(decimal.tojson(), 'NumberDecimal("1.1")');

0 commit comments

Comments
 (0)