【问题标题】:JS in Sublime Text 3 with Node.js Build system带有 Node.js 构建系统的 Sublime Text 3 中的 JS
【发布时间】:2018-01-24 08:10:32
【问题描述】:

我正在使用 Node 9.4.0 作为构建系统在 sublime text 3 中执行 JS 代码。我想知道为什么当我跑步时:

function Person () {     }

var manu = new Person();

console.log(Person.prototype)

我明白了:

Person {}

但是当我从 Chrome 控制台运行它时,我得到:

{constructor: ƒ}
  constructor: ƒ Person()
  __proto__: Object

如何让 Node 显示 Person.prototype 的内容?

为什么显示为空?

感谢您的回答。

【问题讨论】:

    标签: javascript node.js sublimetext3 build-system


    【解决方案1】:

    根据另一个question/answer,看起来你可以做类似的事情

    console.log(Object.getOwnPropertyNames(Person.prototype))
    

    【讨论】:

      【解决方案2】:

      这里不需要使用“new”关键字,你可以将它作为简单的函数运行。但是 对于 "new" 关键字,它会将其转换为构造函数,因此 Person.prototype 如果您正在运行,则指的是高级对象,即窗口 将其转换为结构的控制台

      对于经验:-

      function Person () {     }
      
      var manu = new Person();
      
      //var manu = Person(); 
      

      【讨论】:

        猜你喜欢
        • 2015-03-01
        • 1970-01-01
        • 2013-01-03
        • 1970-01-01
        • 2014-10-21
        • 2013-10-14
        • 2011-12-25
        • 2018-04-27
        相关资源
        最近更新 更多