开发者

Why do all canvas examples use ctx?

Is this a requ开发者_Python百科irement or a convention? If it's a convention what's the reason? Ctx doesn't seem especially memorable or intuitive.

e.g.

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.


It's a convention, since the canvas in the mostly open-source browsers uses Cairo, and in Cairo, they're called "Contexts".


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 :)


Propably because the examples are teaching something, and who wrote wanted to make sure the reader knows ctx is the canvas context since ctx is an abreviation of context, but it's too boring to write "context" when you could just write "ctx".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜