简体   繁体   English

为什么所有画布示例都使用ctx?

[英]Why do all canvas examples use ctx?

Is this a requirement or a convention? 这是一项要求还是一项惯例? If it's a convention what's the reason? 如果这是一个约定是什么原因? Ctx doesn't seem especially memorable or intuitive. Ctx似乎并不特别令人难忘或直观。

eg 例如

var ctx = document.getElementById('canvas').getContext('2d');

It is a shorthand for the word "context". 它是“上下文”一词的简写。 That's it. 而已。

Of course you can use whatever name you like - there is no real naming convention in this instance. 当然,您可以使用您喜欢的任何名称 - 在此实例中没有真正的命名约定。

It is just name for variable. 它只是变量的名称。 It could be anything. 它可能是任何东西。 Ctx is just short word for ConTeXt . Ctx只是ConTeXt的简称。

这是一个惯例,因为大多数开源浏览器中的画布使用Cairo,而在开罗,它们被称为“上下文”。

it's exactly the same if you do 如果你这样做,那就完全一样了

var context = document.getElementById('canvas').getContext('2d');

or 要么

var whatever = document.getElementById('canvas').getContext('2d');

I think "ctx" is really explanatory and short enough :) 我认为“ctx”真的是解释性的,足够短:)

可能是因为这些例子正在教授一些东西,并且写的人想要确保读者知道ctx是画布上下文,因为ctx是上下文的缩写,但是当你可以写“ctx”时写“上下文”太无聊了。

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

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