如何 console.log 所有继承的属性? [英] How to console.log all inherited properties?

查看:57
本文介绍了如何 console.log 所有继承的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,菜鸟问题.我只是在学习 JavaScript.

Sorry for noob question. I'm just learning JavaScript.

我有一个简单的对象.

var bike = {
  wheels: 2,
};

我创建了一个通过 create() 继承所有自行车值的新对象,并向新对象添加了一些新属性.

I create a new one that inherits all the bike values via create() and add some new properties to new Object.

var raleigh = Object.create(bike);
raleigh.color = 'red';

当我在新的 raleigh 对象上执行 console.log 时,我看不到从自行车对象继承的属性.

When I do console.log on new raleigh Object I can't see propeties inherited from bike Object.

console.log(raleigh);

日志是:

{ color: 'red' }

如何登录到控制台包括这些继承的所有属性?

How to log to console all properties including these inherited?

推荐答案

当一个对象通过 console.log 打印时,它会打印出它自己的所有属性和一个指向它继承的对象的链接从.您可以在控制台中看到所有继承的属性,您只需要遵循显示对象的原型链(通常使用 __proto__[[prototype]] 键).

When an object is printed through console.log, it is printed with all its own properties and a link to the object it inherits from. You can see all the inherited properties in console, you just need to follow the prototype chain of the displayed object (typically using __proto__ or [[prototype]] keys).

这篇关于如何 console.log 所有继承的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆