I find bind()
being the cleanest solution so far:
this.bar.onclick = this.ClickEvent.bind(this);
BTW the other this
is called that
by convention very often.
More Related Contents:
- Preserving a reference to “this” in JavaScript prototype functions [duplicate]
- How adding event handler inside a class with a class-method as the callback?
- Use of ‘prototype’ vs. ‘this’ in JavaScript?
- Javascript call() & apply() vs bind()?
- Constructors in JavaScript objects
- Why is JavaScript bind() necessary?
- What is “undefined x 1” in JavaScript?
- Arrow Functions and This [duplicate]
- Clone Object without reference javascript [duplicate]
- What does it mean that Javascript is a prototype based language?
- The invocation context (this) of the forEach function call
- Properties of Javascript function objects
- Does using $this instead of $(this) provide a performance enhancement?
- jQuery: $().click(fn) vs. $().bind(‘click’,fn);
- Are event handlers in JavaScript called in order?
- Why are my JavaScript object properties being overwritten by other instances?
- Object oriented javascript with prototypes vs closures
- Javascript OOP best practices? [closed]
- Objects don’t inherit prototyped functions
- What does `new` in JavaScript do, anyway? [duplicate]
- jQuery: more than one handler for same event
- Save access to this scope
- clearRect not working
- JavaScript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events
- Why does String.prototype log it’s object like a standard object, while Array.prototype logs it’s object like a standard array?
- Is John Resig’s Javascript inheritance snippet deprecated?
- What does “this” mean in a nodejs module?
- Does ECMAScript 6 have a convention for abstract classes? [duplicate]
- How do I create an abstract base class in JavaScript?
- How to register multiple external listeners to the same selection in d3?