如何在事件处理程序的回调中将上下文传递给方法?

How to pass context to method in a callback from event handler?

我总是在 jQuery 中编写事件处理程序,如下所示:

$('.some-class').click(function() {
    alert('bla');
});

我了解到最好避免在回调中使用匿名函数,所以我正在尝试这种方式:

var function someMethod = function() {
    alert('bla');
};

$('.some-class').click(someMethod);

如何将对我单击的元素的引用传递给 someMethod

使用this

var someMethod = function() {
  console.log(this); // => <button class="some-class">OK</button>
  console.log($(this).text()); // => OK
};

$('.some-class').click(someMethod);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="some-class">OK</button>