I have following CS code snippet:
class Ctrl
constructor: (@security) ->
...
isAuthenticated: -> @security.isAuthenticated()
which is translated to following JS:
Ctrl = (function() {
function Ctrl(security) {
this.security = security;
...
}
Ctrl.prototype.isAuthenticated = function() {
return this.security.isAuthenticated();
};
})()
As you can see isAuthenticated
is a simple delegation to security
object's method and creating anonymous function is redundant.
I want to avoid creating this additional call level and instead perform kind of 'inline delegation' which would translate to JS similar to:
Ctrl = (function() {
function Ctrl(security) {
this.security = security;
...
}
Ctrl.prototype.isAuthenticated = this.security.isAuthenticated;
})()
Following doesn't work, since it tries to bind @security
to wrong object:
class Ctrl
constructor: (@security) ->
...
isAuthenticated: @security.isAuthenticated
Any clues ?
prototype
, as @muIsTooShort mentioned :/ – Cambrel