A challenge to the {?}?



  • Help me understand the example, which is the challenge of the function with the first argument in the form of the numbers? Is that an argument for the object or something?

    The movement of the circumference element itself is kind of clear. The only thing that's interesting is how to get into the responsibilities to keep the county center at the center of the element. I guess. this.offsetX, У?

    In the example, the function is:

    <div class="css" onClick="animation({}, this);"></div>
    

    The function itself.

    function animation(args, elem) { // некоторые аргументы определим на будущее
        var $ = {
            radius  :     250, // радиус окружности 
            speed   :     20 // скорость/задержка ( в js это мс, например 10 мс = 100 кадров в секунду)
        }
        var f = 0;
        var s = 2 * Math.PI / 180; //Вычислим угол
        setInterval(function() { // функция движения 
            f += s; // приращение аргумента
              elem.style.left =  235 + $.radius * Math.sin(f)  + 'px'; // меняем координаты элемента, подобно тому как мы это делали в школе в декартовой системе координат. Правда, в данном случае используется полярная система координат, изменяя угол
              elem.style.top =   235 + $.radius * Math.cos(f) + 'px';
        }, $.speed)
    }
    


  • Yeah, in that case, a new empty object.

    Details can be read: https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Grammar_and_types#.D0.9B.D0.B8.D1.82.D0.B5.D1.80.D0.B0.D0.BB_object

    Literal object is a list. zero or more couples consisting of names and related values in parentheses ({}).
    You should not use the literal object at the beginning of the expression, because it would lead to a mistake or to conduct that you do not expect, because the "{" symbol will be interpreted as the beginning of the block.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2