Пользовательское изображение кнопки входа в Facebook в Android Android SDK 3.5

Что-то, что вы можете попробовать, это использовать метод bind, я думаю, что это достигает того, о чем вы просили. Если ничего другого, это все еще очень полезно.

function doClick(elem, func) {
  var diffElem = document.getElementById('some_element'); //could be the same or different element than the element in the doClick argument
  diffElem.addEventListener('click', func.bind(diffElem, elem))
}

function clickEvent(elem, evt) {
  console.log(this);
  console.log(elem); 
  // 'this' and elem can be the same thing if the first parameter 
  // of the bind method is the element the event is being attached to from the argument passed to doClick
  console.log(evt);
}

var elem = document.getElementById('elem_to_do_stuff_with');
doClick(elem, clickEvent);
16
задан Community 23 May 2017 в 12:26
поделиться