summaryrefslogtreecommitdiff
path: root/js/console.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/console.ts')
-rw-r--r--js/console.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/js/console.ts b/js/console.ts
index 002be6e2f..ed2543a9d 100644
--- a/js/console.ts
+++ b/js/console.ts
@@ -326,7 +326,9 @@ function createObjectString(
value: {},
...args: [ConsoleContext, number, number]
): string {
- if (value instanceof Error) {
+ if (customInspect in value && typeof value[customInspect] === "function") {
+ return String(value[customInspect]!());
+ } else if (value instanceof Error) {
return String(value.stack);
} else if (Array.isArray(value)) {
return createArrayString(value, ...args);
@@ -752,6 +754,11 @@ export class Console {
}
}
+/** A symbol which can be used as a key for a custom method which will be called
+ * when `Deno.inspect()` is called, or when the object is logged to the console.
+ */
+export const customInspect = Symbol.for("Deno.customInspect");
+
/**
* `inspect()` converts input into string that has the same format
* as printed by `console.log(...)`;