coffee-script
coffee-script copied to clipboard
Is there a way to set `this` to what it would be in a normal callback
I want to do something like this:-
await namespace 'Util.Logging', defer this
@something = ->
instead of:-
await namespace 'Util.Logging', defer Util
Util.something = ->
namespace being:
@namespace = (target, name, block) ->
[target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
top = target
target = target[item] or= {} for item in name.split '.'
block.call target, target, top
The goal being avoid nesting every module and make use of @ syntax for DRYness.