本文目录

Deno.inspect

🌙
手机阅读
本文目录结构

inspect

  • inspect(value: unknown, options?: InspectOptions): string

  • 不稳定:字符串输出的确切形式仍在考虑,可能会更改。

    UNSTABLE*: The exact form of the string output is under consideration and may change.

    将输入转换为与 console.log() 打印格式相同的字符串。

    Converts the input into a string that has the same format as printed by console.log().

     const obj = {};
     obj.propA = 10;
     obj.propB = "hello"
     const objAsString = Deno.inspect(obj); //{ propA: 10, propB: "hello" }
     console.log(obj);  // 输出与 objAsString 相同的值,例如: { propA: 10, propB: "hello" }
    

    你还可以通过对象上的 Deno.symbols.customInspect 函数 注册自定义的 inspect function,以控制和自定义输出。

    You can also register custom inspect functions, via the customInspect Deno symbol on objects, to control and customize the output.

     class A {
       x = 10;
       y = "hello";
       [Deno.symbols.customInspect](): string {
         return "x=" + this.x + ", y=" + this.y;
       }
     }
    
     const inStringFormat = Deno.inspect(new A()); //"x=10, y=hello"
     console.log(inStringFormat);  // 输出 "x=10, y=hello"
    

    同时还提供了一些输出选项。

    Finally, a number of output options are also available.

     const out = Deno.inspect(obj, {showHidden: true, depth: 4, colors: true, indentLevel: 2});
    

参数

-   ##### value: unknown

-   ##### Optional options: [InspectOptions](interfaces/deno.inspectoptions.html)

返回 string

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了