I
I
Isaac Clark2012-11-02 22:30:41
JavaScript
Isaac Clark, 2012-11-02 22:30:41

What does the code mean?

Hello, tell me please.
I found the code in which the author builds a field for the game.

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


for (var i in context)
{
    context[i[0] + (i[4] || '')] = context[i];
    console.log(context[i]);
}

At the same time, it refers to this site.
// make shortcuts for canvas ops // http://marijnhaverbeke.nl/js1k/
Please tell me what this code means, the properties and methods of the canvas are displayed in the console, but I don’t understand why this is needed and why it takes step 0 and 4 ?!
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaliy Petrychuk, 2012-11-02
@Dark_Knight

It's just a reference to another method. Thus, the author will be able to access the method not context.longLongMethod, but context.lL (or not context.meth, but context.m)

A
Alexander Rudevich, 2012-11-04
@rudevich

strange decision, but interesting.

P
Pavlo Ponomarenko, 2012-12-22
@TheShock

Pay attention to the URL:
http://marijnhaverbeke.nl/ js1k
This feature is needed for very small code competitions. In real applications, of course, such crap should not be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question