简体   繁体   English

在Firefox DevTools变量视图中显示值而不是getter / setter函数

[英]Show values instead of getter/setter functions in Firefox DevTools variable view

When inspecting a JavaScript object, that uses getter/setter functions for properties (defined with Object.defineProperties ) in the Firefox DevTools variables view, it shows the defined getter and setter functions for this particular property: 检查JavaScript对象时,它使用Firefox DevTools变量视图中的属性(使用Object.defineProperties定义)的getter / setter函数,它显示了此特定属性的已定义的getter和setter函数:

在此输入图像描述

Is there any way to show the actual content instead of the functions in this view? 有没有办法显示实际内容而不是此视图中的功能?

Edit: as nils commented, viewing the actual content means technically invoking the getter. 编辑:正如nils评论的那样,查看实际内容意味着从技术上调用getter。

Since Firefox 65 this is possible to invoke a getter via a button next to it within the logged object. 从Firefox 65开始,可以通过记录对象中旁边的按钮调用getter。

用于调用getter的按钮

This was implemented in bug 820878 resp. 这是在bug 820878中实现的。 issue 6140 on GitHub . 在GitHub上发布6140

In versions prior to Firefox 65 you could output the getter's return value by simply calling it directly via the command line. 在Firefox 65之前的版本中,只需通过命令行直接调用它即可输出getter的返回值。

An alternative is to use this workaround - instead of logging the object: 另一种方法是使用此解决方法 - 而不是记录对象:

console.log(objectVar)

You can assign the current state into an empty object and then log it: 您可以将当前状态分配给空对象,然后将其记录下来:

console.log(Object.assign({}, objectVar)) // works on all browsers
// OR
console.log({...objectVar}) // es6 only

Sidenote: writing this gets tedious fast so if you use a code editor (Atom/VScode) then you can add this as a snippet 旁注:写这个很快很快,所以如果你使用代码编辑器(Atom / VScode)那么你可以将它添加为一个片段

Here is an example snippet where you can just type 'l' then press tab: 这是一个示例代码段,您只需键入“l”,然后按Tab键:

'.source.js':
  'console.log object':
    'prefix': 'l'
    'body': "console.log('${1:variable}', Object.assign({}, ${1:variable}))"

OR for ES6: 或ES6:

'.source.js':
      'console.log object':
        'prefix': 'l'
        'body': "console.log('${1:variable}', {...${1:variable}})"

Firefox will display incorrectly object properties gathered from for example API, but values created instantly in context are shown properly. Firefox将显示从例如API收集的错误对象属性,但正确显示在上下文中立即创建的值。 I found a workaround with lodash library ( https://lodash.com/ ) Or eventually it is possible to do it with another js framework, which is able to fully clone object. 我找到了lodash库( https://lodash.com/ )的解决方法,或者最终可以使用另一个能够完全克隆对象的js框架。

  console.dir(_.cloneDeep(objectToShowInConsole))

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM