maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
727 stars 58 forks source link

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

Open vjpr opened 10 years ago

vjpr commented 10 years ago

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.