为什么document.createElement('canvas')。getContext('2d')。 hasOwnProperty('font')返回false?

时间:2018-04-09 06:03:36

标签: javascript canvas

为什么hasOwnProperty('font')返回false,而返回的对象具有此属性。

var ctx = document.createElement('canvas').getContext('2d');
console.log(ctx.hasOwnProperty('font'));
console.log(ctx.font);

这是document.createElement('canvas')。getContext('2d')的键的屏幕截图,我们可以看到它具有font属性。 A screenshot of a console log where indeed the font property is logged as well as other properties of the CanvasRenderingContext2D object

1 个答案:

答案 0 :(得分:1)

也许是因为font不是上下文的简单属性,而是getter和setter函数对。

相关问题