Problem

In any programming language with both first class functions and objects, the handling of a this parameter is a cause for complication. In the case of JavaScript the picture is particularly sticky due to langauge foibles. An additional complication, ClojureScript does not have its own notion of this independent to its JavaScript interop. Currently, there is no good way to refer to a JavaScript this aside from the (js* "this") hack. ClojureScript should more effectively handle this in a way that is safe and intuitive.

A bit about this in general

ClojureScript functions are compiled to JavaScript functions and are therefore subject to the implicit this behavior.

Given a function f defined as:

function f(a,b) {
print([this,a,b])
}

Calling f directly yields:

f(1,2)
// [object global],1,2

note: in JavaScript strict mode this would be bound to undefined in the previous example

In this case, the this variable is implicitly bound to the global object.

However, when bound as a property on an object, f's implicit this changes: