Как обновить запись монго, используя Rogue с MongoCaseClassField, когда класс case содержит перечисление scala

Резюме this Javascript:

  • Значение this определяется тем, как функция вызывается не, где она была создана!
  • Обычно значение из this определяется Объектом, который остается от точки. (window в глобальном пространстве)
  • В случае прослушивателей значение this относится к элементу DOM, на котором было вызвано событие.
  • Когда функция вызывается с помощью new ключевое слово значение this относится к вновь созданному объекту
  • Вы можете управлять значением this с помощью функций: call, apply, bind

Пример:

let object = {
  prop1: function () {console.log(this);}
}

object.prop1();   // object is left of the dot, thus this is object

const myFunction = object.prop1 // We store the function in the variable myFunction

myFunction(); // Here we are in the global space
              // myFunction is a property on the global object
              // Therefore it logs the window object
              
             

Пример прослушивателей событий:

document.querySelector('.foo').addEventListener('click', function () {
  console.log(this);   // This refers to the DOM element the eventListener was invoked from
})


document.querySelector('.foo').addEventListener('click', () => {
  console.log(this);  // Tip, es6 arrow function don't have their own binding to the this v
})                    // Therefore this will log the global object
.foo:hover {
  color: red;
  cursor: pointer;
}
<div class="foo">click me</div>

Пример конструктора:

function Person (name) {
  this.name = name;
}

const me = new Person('Willem');
// When using the new keyword the this in the constructor function will refer to the newly created object

console.log(me.name); 
// Therefore, the name property was placed on the object created with new keyword.

128
задан Usman Maqbool 25 June 2015 в 08:46
поделиться