Consider the following code:
class dom_listener_list =
object (self)
val mutable the_list : Dom_html.event_listener_id list = []
method add_event_listener (typ : 'a Dom_html.Event.typ) (handler : Dom_html.pointerEvent Js.t -> bool Js.t) : unit =
let listener = Dom_html.addEventListener Dom_html.window typ (Dom.handler handler) Js._true in
the_list <- listener :: the_list
method remove_all_listeners =
List.iter ~f:Dom_html.removeEventListener the_list;
the_list <- []
end
The compiler complains:
15 | object (self)
^^^^^^
Error (warning 27 [unused-var-strict]): unused variable self.
Now, this confuses me: isn’t the use of the_list
an implicit use of self
? Without using self
, how we are accessing the_list
?