开发者

How to override object's display name in DevTools console?

I am using Dean Edwards' Base.js library to provide OOP in javascript. The objects it creates look like "klass.proto.constructor" in Chrome's console. Is it possible to override its display name to show human-readable labels like "MyClass" etc.

I think it could be achieved by playing with toString property, but i 开发者_高级运维have no idea how to do this.


In the Chrome console, the object's toString isn't called. Instead there is an interactive representation of the object's structure.

See my answer to a similar question:

https://stackoverflow.com/a/31351527/2482570


If I'm not mistaken, you would set

Your_object.prototype.toString = function() {
    return "MyClass"; /* or whatever */
}

If you need to do this on a regular basis for all the objects returned from Base.js, you have to patch the library :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜