coffee-script icon indicating copy to clipboard operation
coffee-script copied to clipboard

Is there a way to set `this` to what it would be in a normal callback

Open vjpr opened this issue 11 years ago • 0 comments

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.

vjpr avatar Feb 05 '14 09:02 vjpr