Вам необходимо создать переменную, которая будет храниться в области закрытия функции onkeyup
:
function FilterSelect(select, search) {
var _this = this; // <-- win
_this.select = select;
_this.search = search;
// Get the current list options
_this.options = this.select.options;
// Whenever the text of the search box changes, do this
_this.search.onkeyup = function() {
// Clear the list
while(this.select.options.length > 0) {
_this.select.remove(0);
}
}
}
Делая это, вы гарантируете, что на правильное значение будет ссылаться независимо от того, из какой области вызывается функция onkeyup
(обычно это глобальная область / область окна из-за событий).
РЕДАКТИРОВАТЬ
На самом деле, если вам просто нужен доступ к select
, вы уже можете сделать это:
this.search.onkeyup = function() {
// Clear the list
while(this.select.options.length > 0) {
select.remove(0);
}
}