`context.canvas.width` 和 `canvas.width` 有什么区别?
What is the difference between doing `context.canvas.width` and `canvas.width`?
当使用 HTML5 元素 Canvas 时,context.canvas.width
和 canvas.width
有什么区别?同样 ... .height
.
两个名称一个引用对象
没有区别,因为 context.canvas
与 canvas
是同一个对象,假设您从 canvas.
创建了上下文
// They are the same when the strict equality is true.
const context = canvas.getContext("2d");
console.log(context.canvas === canvas); // >> true
变量context
引用了一个CanvasRenderingContext2D
with the property CanvasRenderingContext2D.canvas
that references the HTMLCanvasElement
, named canvas
, used to get context
via the call HTMLCanvasElement.getContext("2d")
当使用 HTML5 元素 Canvas 时,context.canvas.width
和 canvas.width
有什么区别?同样 ... .height
.
两个名称一个引用对象
没有区别,因为 context.canvas
与 canvas
是同一个对象,假设您从 canvas.
// They are the same when the strict equality is true.
const context = canvas.getContext("2d");
console.log(context.canvas === canvas); // >> true
变量context
引用了一个CanvasRenderingContext2D
with the property CanvasRenderingContext2D.canvas
that references the HTMLCanvasElement
, named canvas
, used to get context
via the call HTMLCanvasElement.getContext("2d")